4 ms·
As far as I know, a (C-like) language must either have: - A statement separator (semicolons) - Significant whitespace Otherwise parsing the language is very
by paavohtl 6y ago
As far as I know, a (C-like) language must either have:
- A statement separator (semicolons)
- Significant whitespace
Otherwise parsing the language is very likely ambiguous, e.g JavaScript [1] [2].
[1] https://flaviocopes.com/javascript-automatic-semicolon-insertion/ https://flaviocopes.com/javascript-automatic-semicolon-inser...
[2] https://medium.com/better-programming/you-might-need-those-semicolons-in-your-javascript-after-all-b28154f93ea8 https://medium.com/better-programming/you-might-need-those-s...
- hu3 6y agoGo doesn't have either: https://play.golang.org/ https://play.golang.org/
- paavohtl 6y agoAh, but it does. Statements are separated by newlines. That is the same as significant whitespace (or a statement separator; you can interpret it either way).
- hu3 6y agoTechnically correct. But the point is about ergonomy. Go doesn't require semicolons neither indentation. That coupled with gofmt auto-formatter makes coding more pleasant.
- duckerude 6y agoJavaScript messed it up, but Python did it well. A newline is a statement separator, unless it's e.g. between parentheses where a statement separator wouldn't make sense. Unlike JavaScript, that means you don't have to look at the next line to figure out whether the statement continues. JavaScript assumes a newline doesn't end a statement, until proven otherwise. Python assumes it does end a statement unless it very clearly can't. It's independent from Python's other significant whitespace, so you could use it in a more "C-like" syntax. But it wouldn't be a good fit for Rust. In Rust, leaving the semicolon off the final statement in a block already changes its meaning, so that would become ambiguous. It also uses method chaining syntax a great deal more than Python, which is a bit awkward because you have to wrap the expression in parentheses (though autoformatting helps). And of course it would break most existing code.
- jolux 6y agoSwift and Go don't have either. Neither does Kotlin. The difference is that Rust is an expression language (much like ML), and the semicolon determines whether the resulting expression is returned or thrown away. OCaml needs semicolons when you're doing imperative programming too.
- johncolanduoni 6y agoSwift, Go, and Kotlin all take newlines into account. I guess one could have a definition of “significant whitespace” that excludes that but in any case I strongly suspect that’s what they were referring to.
- jolux 6y agoyes, but I believe they support semicolons as a statement separator on the same line
- deleted 6y ago[deleted]