Question

So, across my programming experience I have come across two types of type annotations for statically typed languages: I call them 'before' and 'after'. C-Style languages use the format

int i = 5

While most non-c-family languages use the format

var c:int = 5

Examples of the former category would be C, C++, Java; examples of the latter category would be Scala, Haxe, Go.

This may seem to some to be superficial, but my question is: what are the advantages of each style? Why use one over the other? Why did C adopt that style in the first place?

Was it helpful?

Solution

The machine doesn't care - it's just that people who designed certain languages felt that some types of syntax are better or more easily readable than the others. Modern compilers usually have several stages of processing, and almost all of this syntactic differences are usually lost after the first stage, which parses text and converts then into compiler internal structures (AST - abstract syntax tree).

There are some historical precedences, e.g. the "prefix" vs "infix" vs "postfix" notation (http://en.wikipedia.org/wiki/Polish_notation, http://en.wikipedia.org/wiki/Infix_notation, http://en.wikipedia.org/wiki/Reverse_Polish_notation) which in the context of computer engineering history were used in edge cases - e.g. the "infix" notation is usually harder to parse and requires more memory than the postfix/RPN notation so it was not used where resources were really scarce (several KiB of memory or less), but most of those reasons are now obsolete as hardware is powerful enough.

Today, when designing a language, the choice of such syntax details is influenced by trying to make the language similar to some other popular language or group of languages for which there are already existing programmers, to avoid making a "language from Mars" which few people will use.

tl;dr: Depends on the person who created the language and what he though is more readable or "the right thing to do").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top