0

This question already has an answer here:

Modern languages like Rust, Kotlin, and TypeScript, define their syntax to declare variables as:

myVariableName: VariableType

As opposed to the C-like approach not so old languages like JavaScript, C#, and Java take:

VariableType myVariableName

My question is, why the new trend? What was wrong with the old syntax and what makes the new syntax better?

marked as duplicate by gnat, Robert Harvey, Telastyn, Dan Pichelman, Walfrat Oct 5 '18 at 14:40

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.

  • This notation goes back at least to 1902. You have a strange definition of "new trend". – Jörg W Mittag Oct 7 '18 at 14:31
2

It isn't a new trend.

To the best of my knowledge, this convention first appeared in Nicklaus Wirth's PASCAL language, which was designed (according to Wikipedia) in 1968-1969 and first published in 1970.

The other form dates back to at least ALGOL60, from 1960.

The issue is that, when the language follows C declaration syntax, the syntax gets muddy if the declaration is at all complicated: the name of the entity being declared gets buried somewhere in the middle. With the PASCAL style, the name is always on the left of the colon and the type is on the right, making it easier to separate the two parts.

  • With the old style, the name is always on the right and type is on the left, making it easier to separate the two parts ;) – Fabio Oct 5 '18 at 19:30
  • @Fabio. Nope. Take a look at arrays of pointers, or, worse, arrays of function pointers. – John R. Strohm Oct 5 '18 at 19:40
  • 3
    I think Fabio is saying your point is better made when more then name and type are involved. When it's just two words it's a coin flip. – candied_orange Oct 5 '18 at 20:10
  • @candied_orange: The problem is that the cases where you NEED to be able to see the name quickly and easily are almost never the easy ones, that involve JUST a name and a typename. – John R. Strohm Oct 8 '18 at 14:56
  • 1
    @JohnR.Strohm we're not saying you're wrong. We're saying with an edit you could make the point clearer. More comments aren't going to help. – candied_orange Oct 8 '18 at 15:37

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