4 ms·
The trend towards optional semicolons isn't good. Javascript, Go, and Rust all have different semicolon syntax and semantics.
by Animats 11y ago
The trend towards optional semicolons isn't good. Javascript, Go, and Rust all have different semicolon syntax and semantics.
- __david__ 11y agoSo do Lisp, Haskell, OCaml, Python, and Perl. They're all different languages and should be expected to have grammatical differences. This is not a new trend.
- ansible 11y agoI can't speak for the other two (just learning Rust), but with Go, the auto-insertion of semi-colons has not caused me any problems. It just works.
- nvader 11y agoThe essential difference between Javascript and Go is that in Go, the semicolons are inserted by the lexer[0], while in JS, they're inserted by the parser. I don't know how Rust does it. This means that Go's semicolon insertion rules are really simple: to judge if a statement will end in a semicolon, you only need to examine that line (actually, the last token of that line). In Javascript, on the other hand, the start of the next line needs to be considered as well. If the two lines could possibly be interpreted as one statement together, then they are (except for restricted productions). [ and ( are common offenders that cause lines to "pick up" other lines, but unary + and - can also be candidates when they get promoted to binary operators. [0] https://golang.org/doc/effective_go.html#semicolons https://golang.org/doc/effective_go.html#semicolons
- steveklabnik 11y agoRust doesn't do any special insertion/deletion, but take an expression and add a ; and it becomes a statement.