4 ms·
The origin and virtues of semicolons in programming languages
- 082349872349872 3y agoMany are aware of ; in C but fewer of ,
- pavlov 3y agoThe for loop statement is maybe the likeliest place to encounter the comma operator. E.g. if you wanted to increment two values: for (x=0, y=100; x<10; x++, y+=20)
- GrumpySloth 3y agoFun fact: , in C is what ; is in ML.
- Koshkin 3y agoFun fact: in Greek, the semicolon is the question mark. (Actually, the regular question mark looks like an overturned and exaggerated semicolon.)
- netmare 3y agoAlthough 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...
- mrbluecoat 3y agoIn the JavaScript world, tread cautiously on this passionate topic. https://github.com/twbs/bootstrap/issues/3057 https://github.com/twbs/bootstrap/issues/3057
- dvh 3y agoI 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".
- ethagnawl 3y agoI'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. (^ From https://eslint.style/rules/js/semi https://eslint.style/rules/js/semi) Stop being cute and just use semicolons.
- hombre_fatal 3y ago> 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.”
- ethagnawl 3y ago> I haven’t used a trailing semicolon in probably ten years. I haven't used my seat belt in ten years and bangs roof I'm doing just fine!
- hombre_fatal 3y agoThis 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.
- adrian_b 3y agoAs 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.
- greenyoda 3y agoAnother early language that used semicolons as statement separators was PL/I, which appeared in 1964: https://en.wikipedia.org/wiki/PL/I https://en.wikipedia.org/wiki/PL/I
- teo_zero 3y agoLet's not forget that BASIC used the colon.
- netmare 3y agoAnd that the semicolon was used as a PRINT statement terminator when you wanted to suppress the implicit newline at the end.
- teo_zero 3y agoRight! 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.
- librasteve 3y agoraku 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” https://docs.raku.org/ https://docs.raku.org/
- VS1999 3y ago[flagged]
- karmakaze 3y agoWhen 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.
- jacknews 3y ago"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.