The origin and virtues of semicolons in programming languages
ntietz.com
ntietz.com
The next important point in its history is in the language CPL (in its version described in January 1966), where the statement separator could be either the semicolon or the new line, whichever was convenient.
This feature of CPL has been inherited by the UNIX shell and by many other programming languages where the semicolon is used only for writing multiple statements on a single line.
While most such languages use some special character to mark continuation lines, to allow multiple-line statements, the CPL compiler was more clever and it decided automatically when a statement could not be terminated at the end of a line, so that the next line must have been a continuation line.
Emphatically NOT significant-whitespace, which causes all kinds of headaches, for example in an education setting, with cut&paste, etc.
Language structure should be denoted with actual characters, and then automatic formatting (pretty-printing) can confirm the structure is as intended; kind of like double-entry book-keeping.
I just ran across this "JS semicolon topic" again recently while reading Next.js documentation in order to help a colleague debug an issue they were facing. AFAICT, that project's documentation doesn't have a single semicolon anywhere in it. (They're using `const` everywhere, tho! ) What are the odds someone has copied code from those docs and run into a quirk around _automatic semicolon insertion_? They're not zero! I mean, it's simple, you just have to remember that a newline ends a statement ... except when:
> The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement. (For instance, ending with . or ,.) > The line is -- or ++ (in which case it will decrement/increment the next token.) > It is a for(), while(), do, if(), or else, and there is no { > The next line starts with [, (, +, *, /, -, ,, ., or some other binary operator that can only be found between two tokens in a single expression.
(^ From https://eslint.style/rules/js/semi)
Stop being cute and just use semicolons.
Btw Douglas Crawford’s comments there didn’t age well. He’s wrong on every count (jsmin should follow JS semi rules, semi-less won’t break in the future, it’s only more popular than ever, etc) and just comes off as hot headed and “anyone who likes X is stupid but not me.”
I haven't used my seat belt in ten years and bangs roof I'm doing just fine!
These tools have changed the argument into one over aesthetics which is why opponents have had to grasp for increasingly hypothetical scenarios where the sky falls because the code doesn't use semicolons. Even in the github thread, it starts off concern-trolling over hypothetical day 1 beginners copy-pasting code into Notepad.
That github thread was back in 2012 btw (12 years ago) which was the year of the final throes of the semicolon debate. None of the chicken littling came true. People still upset about semicolons are like that Japanese soldier still hiding in the Philippines in the 1970s thinking WW2 is raging, except they refuse to admit it's just a style preference.
- statement line separator;
- loop($i=0;$i++;$i<3){…} *
- multi dimensional subscripts @a[^3;^3;^3]
- list of list literals (1,2; 3,4) eqv ((1,2), (3,4));
to paraphrase Larry Wall “everyone wants the [semi] colon” for (x=0, y=100; x<10; x++, y+=20)