No Semicolons Needed

41 points by eBPF


carlana

JavaScript seems to be the language that has given Automatic Semicolon Insertion a bad reputation.

ASI in JavaScript was a huge mistake. Of all languages, one that was designed from the start to be inserted into HTML and sent from computers that use Unix line endings to ones that use Windows line endings (and back then Mac line endings!) should never have had an automatic insertion rule!

Basically every other language should, yes, optimize the common case and omit semicolons on normal lines and have some kind of continuation character for long lines. JavaScript however needed an explicit delimiter for its intended environment and somehow didn't get it!

kroisse

This is interesting that Haskell is not in the list. In my opinion, it has a similar rule to 'a different idea' the author mentions.

ekuber

I used to hate semicolons. Then I started working in parser recovery for rustc. I now love semicolons.

Removing redundancy from syntax should be a non-goal, an anti-goal even. The more redundancy there is, the higher the likelihood of making a mistake while writing, but the higher the ability for humans and machines to understand the developer's intent unambiguously.

Having "flagposts" in the code let's people skim code ("I'm only looking at every pub fn") and the parser have a fighting chance of recovering ("found a parse error inside of a function def, consume everything until the first unmatched } which would correspond to the fn body start and mark the whole body as having failed parsing, let the rest of the compiler run"). Semicolons allow for that kind of recovery. And the same logic that you would use for automatic semicolon insertion can be used to tell the user where they forgot a semicolon. That way you get the ergonomics of writting code in a slightly less principled way while still being able to read principled code after you're done.

injuly

This is a nice list. Lua is my favorite among those mentioned.

Haskell and OCaml are two languages that would make good entries. They both deal with whitespace pretty well despite having distinct approaches.

Haskell is whitespace sensitive, but the programmer can add braces and semi-colons to "override" the newline rules.

OCaml code often looks like it's whitespace sensitive, but really it isn't. Just very intentionally designed grammar, much like Lua.