- 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-inser...
[2] https://medium.com/better-programming/you-might-need-those-s...
But the point is about ergonomy. Go doesn't require semicolons neither indentation. That coupled with gofmt auto-formatter makes coding more pleasant.
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.
return
x;
turns into: return;
x;
which is clearly not what was intended. Sure, if Rust copied JavaScript’s algorithm, the compiler would throw a type error (where () is not compatible with typeof(x)) and complain of dead code instead of silently failing, but it seems like a hard task. Then again, I’m not a compiler writer.Many languages restrict statement-expressions to function calls and other expressions with explicit side-effects.
Another choice would be to avoid syntax where you can optionally append expressions to an otherwise complete statement (so only one of "return" and "return expr" are allowed, and the other has an alternate spelling)
Or the parser could forbid line continuation in the absence of a trailing binary operator, which makes mid-statement newlines illegal outside of a highly visible special case so users would be trained out of inserting them at random before they introduced errors.
Both JavaScript and python do something like the last one but both screw it up; JavaScript also allows leading operators and open-brackets to continue the previous line which is a huge mess, and python uses brackets to continue lines but parens are both optional around most expressions and overloaded (generators, tuples). If you wanted to go that way you would need a bracket that meant "this is syntactically a single expression and has no other meaning"
return \
x;What's wrong with semicolons anyway?