[HN Gopher] The origin and virtues of semicolons in programming ...
___________________________________________________________________
The origin and virtues of semicolons in programming languages
Author : nalgeon
Score : 31 points
Date : 2024-04-15 10:34 UTC (12 hours ago)
(HTM) web link (ntietz.com)
(TXT) w3m dump (ntietz.com)
| 082349872349872 wrote:
| Many are aware of ; in C but fewer of ,
| pavlov wrote:
| The 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 wrote:
| Fun fact: , in C is what ; is in ML.
| Koshkin wrote:
| Fun fact: in Greek, the semicolon is the question mark.
| (Actually, the regular question mark looks like an overturned and
| exaggerated semicolon.)
| mrbluecoat wrote:
| In the JavaScript world, tread cautiously on this passionate
| topic. https://github.com/twbs/bootstrap/issues/3057
| dvh wrote:
| 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".
| ethagnawl wrote:
| 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.
|
| (^ From https://eslint.style/rules/js/semi)
|
| Stop being cute and just use semicolons.
| adrian_b wrote:
| 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.
| greenyoda wrote:
| Another early language that used semicolons as statement
| separators was PL/I, which appeared in 1964:
| https://en.wikipedia.org/wiki/PL/I
| teo_zero wrote:
| Let's not forget that BASIC used the colon.
| netmare wrote:
| And that the semicolon was used as a PRINT statement terminator
| when you wanted to suppress the implicit newline at the end.
| librasteve wrote:
| 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"
|
| https://docs.raku.org/
| karmakaze wrote:
| 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.
___________________________________________________________________
(page generated 2024-04-15 23:01 UTC)