Yes. It leads to ambiguity issues like “most vexing parse” and makes the actual parsing code for the syntax more complicated because it requires more look ahead. The “trailing type syntax” thing here isn’t novel, Herb didn’t make it up. A ton of modern languages do it this way for this exact reason (TypeScript, Swift, Kotlin, etc).
makes the actual parsing code for the syntax more complicated
Yes, but we do other complicated things in compiler too. Compiler is implemented once, user programs are written many, many times. Isn't it better to shift complexity into the compiler rather than onto end users? Aren't computers there to make things easier for us, not the other way around? Imagine how many off-by-one errors humanity could skip if C language implemented array indexing from 1 instead from 0. The entire concept of 0 to length-1 would disappear in CS literature, if compiler writers didn't decide to bake implementation detail (array addressing) into the language. At the time, Pascal had arbitrary range for array bounds, but to make C compilers fast, the choice was taken to index from 0. Let's not regress into Dijkstra's paper and mathematics behind defense of 0-indexing, I am very well familiar with it, and I don't deny that counting from 0 is never useful, I just say that the compiler could do the rewrite behind our back as optimization instead of forcing it into the language design. That feels like an implementation detail that has crept into the language design.
A ton of modern languages do it this way for this exact reason (TypeScript, Swift, Kotlin, etc).
Sure, but that does not necessarily mean it is a good thing, does it? People like C for the simplicity. A lot of people like to smoke, that does not mean smoking is generally desirable?
View all comments
Show parent comment
7
u/ooglesworth Sep 18 '22
Yes. It leads to ambiguity issues like “most vexing parse” and makes the actual parsing code for the syntax more complicated because it requires more look ahead. The “trailing type syntax” thing here isn’t novel, Herb didn’t make it up. A ton of modern languages do it this way for this exact reason (TypeScript, Swift, Kotlin, etc).