-4

This question already has an answer here:

Different programming language always/most of the time use different syntax.

For example take PHP, Java and Python.

  1. In Php & Java semicolons are compulsory at the end of the line, yet Python gives an error if I put semicolon at the end of line.

  2. In PHP & Java we must use brackets for more than 1 statement, whereas it is not required in Python.

  3. In PHP variable should have $ sign while Java & Python does not have it.

  4. Java & Python use + for concatenation of 2 strings whereas PHP uses ..

  5. To import package JAVA uses import statement where as C# uses using statement.

And many, many more.

Why does this differentiation exists? What advantage it gives with different syntax?

Why can't there be a global standard to do all simple and common things?

I don't think this is a duplicate as I say Why is there Different syntax for different languages?. But that question answers Is there anything related to productivity when syntax changes.

marked as duplicate by gnat, user40980, durron597, user53019, user22815 Jul 2 '15 at 11:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    If they had the same syntax then they would be the same language. – James Anderson Jun 30 '15 at 6:21
  • @JamesAnderson Is that true? What if they have same syntax, but different core library? – Euphoric Jun 30 '15 at 6:25
  • Look into Lisp or Scheme (or Clojure) syntax. It is considerably simpler. Also, understand that semantics matters much more than syntax. Look into Prolog vs Java. – Basile Starynkevitch Jun 30 '15 at 6:28
  • Syntax is the language! Its technically possible to have the same syntax implement different behavior. But who is going to write a language where "1 + 1" evaluates to 0. You get oddities where ' "1" + 1 ' is valid syntax in perl, python and javascript -- but each language will give a different answer. – James Anderson Jun 30 '15 at 6:31
  • 3
    @Bartdude The only reason you don't feel comfortable with PHP's use for the dot is because you learned a language that used it differently before you learned PHP. If you had started with Perl (where PHP inherited most of its syntax from), then "un-intuitive and disturbing" would mean using the dot for anything but string concatenation. – yannis Jun 30 '15 at 13:35
9

Why cant be a global Standard to do all Simple and Common things?

We tried that. The concept was called UNCOL, and the idea was that it would be ported to every architecture in the world, everyone would use it for everything. As you can tell, things didn't work out that way.

Why not? Because programming is a complex activity, and there is no single measure by which you can judge one program better than another, as long as both do their jobs. One is faster. The other takes up less RAM when running. The third one is immediately obvious for the maintenance programmer.

Also, people do not agree about what is obvious, easy to understand, well-structured etc. when it comes to source code. You can measure the runtime characteristics of a program, but quality of source code is a subjective matter. Any attempt by one side to impose a coding standard on the entire world because they consider it "the best" would be laughed off the table by a large opposing faction. This is why we will never have a universal programming language.

5

What matters about programming languages are the semantics, not the syntax. However, syntax is a vehicle for semantics. It is easy to show that two languages can have incompatible semantics (e.g. unrestricted pointers vs. memory safety, or differences in type systems). Let's focus on the syntax and semantics of variable declarations.

When we declare a variable in some language, this variable has a type, a scope, and a lifetime.

The lifetime of a variable determines how long the value in that variable exists. Afterwards, that value is freed. In many languages, the lifetime is unrestricted: a value may be used as long as it is accessible, the garbage collector takes care of freeing the associated memory. This means we do not statically know when a value is freed. But C++ guarantees deterministic destruction, and it is a frequent idiom to associate sides effects with destruction. This is not possible with garbage collection. This line has wildly different meaning in C++ and Java/C#:

Type variable = calculation();

An universal syntax would need precise lifetime control syntax to be able to express a variety of languages.

Next up: scoping. Scope determines where an identifier is visible and the variable can be accessed. There are two kinds of scoping: lexical/static and dynamic. With dynamic scoping, a variable is accessible until a certain point in time, and it is accessible from any code that is executed during this time. Examples are Perl's package-global variables or Lisp's “special” variables. More common is lexical scoping, where the variable is only visible within a specific region of source code. There are three ways where the scope of a variable can start:

  • in the statement where the variable is declared, which allows the variable to be used within its definition. This is important if we are writing a recursive lambda expression.
  • after the statement where the variable is declared. This prevents recursive definitions.
  • at a different location, e.g. the start of the enclosing function or an enclosing block.

This statement has a different meaning in JavaScript (function scope) and C# (scope begins in statement):

var variable = calculation();

Universal syntax would need to provide precise scope controls for a variety of scoping conventions.

Some languages don't make a syntactic difference between assignment and variable declaration. This is problematic when a language features closures, since this prevents us from assigning to closed-over variables.

Finally, typing. Many languages require explicit static typing, others support some kind of type inference, others have no static types. This line has different semantics in JavaScript and C#:

var variable = calculation();

In JavaScript, variables do not have a fixed type, and we can freely assign a value of a different type to it at a later point. In C#, the var keyword triggers type inference, and the static type is determined by the result type of the assigning calculation. Aside from the scoping differences, the equivalent C# would be:

dynamic variable = calculation ();

And there are various other properties such as reassignability, thread-safety guarantees, or constantness of values that might be reflected in a variable declaration. There is no way a simple statement such as Python's variable = value could be used in an universal syntax. Instead, we might be dealing with

let-in-function mutable thread-local dynamic* variable = value;

And at that point, our universal syntax is so cumbersome and annoying that no one would want to use it. The solution cannot be to rule out some combinations in order to simplify the syntax, because some language will have used that combination by default. If our syntax cannot express the rich variety of programming language semantics, it is hardly an universal syntax.

0

Every programming language is invented by different mind set, experience and objective, and there is no universal guideline setup for creating a language. So whenever a new language comes up it's their inventor choice to think about best naming/ syntax so this is all up to them what they think is best will add there. For example to add two numbers i will create function Like Add() and for me this will be best suitable but other may think Sum() will be best suitable. So it's all mind set they think on that time.

Not the answer you're looking for? Browse other questions tagged or ask your own question.