As this blog says, the semicolon has been introduced as the "statement separator" in December 1958, in the report about the language IAL (International Algebraic Language), which has been rebranded later, in 1960, as ALGOL.
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.
Although they're the same glyph, they are different codepoints in Unicode. There's an old joke about replacing semicolons with Greek question marks in JavaScript and baffling your colleagues...
"I'd love to hear what you would choose in your dream world!"
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'm not going to lie, my blood pressure went up just from skimming that thread. Boy howdy, I don't miss any aspect of JS development, its ecosystem or community.
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.
> Stop being cute and just use semicolons.
Or stop being cute and let ASI insert the semicolon for you. ;)
I haven’t used a trailing semicolon in probably ten years.
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.”
This makes no sense unless you're unaware of tools like Prettier and eslint which are the seatbelt in your analogy (we don't need analogies, please).
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.
I am putting semicolons on the altar in the church of JavaScript so that one particularly difficult day linter will say: "index.js, line 235, character 17: missing closing bracket".
When devising a custom keyboard layout, I had to decide whether semicolons were important or not in my future. I opted to put the comma on right-pinky above home row. The shifted-comma is still a colon though.
raku has a couple (extra) uses for the semi-colon…
- 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”
Right! But it was more than that: it was the separator between data you wanted to print without any blank in-between, as opposed to the comma that would add a Tab.
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.