3 ms·
>but statements like this, >"Whether you like it or not, whitespace is significant in JavaScript. A linebreak indicates, in most cases, the end of a statement;
by chc 15y ago
>but statements like this,
>"Whether you like it or not, whitespace is significant in JavaScript. A linebreak indicates, in most cases, the end of a statement; a semicolon is automatically inserted for you."
>Are just flat out absurd. Like it or not, automatic semicolon insertion is NOT significant whitespace and the second sentence completely contradicts the first by pointing out that ASI happens in MOST cases--but not all. If whitespace were truly significant, it would apply in ALL cases.
I don't mean to gang up on you, but that just isn't right. Will you agree that newlines are significant in both Ruby and Python? Because both of those have cases where newlines are not terminal. So I think this absolutist stance is quite unreasonable.
Automatic semicolon insertion is ipso facto indistinguishable from significant newlines in a language where semicolons are statement terminators — both mean that you can end statements with newlines. The fact that JavaScript's ASI rules have awkward holes just means that its ASI rules have awkward holes. Have a look at Go for an ASI language whose creators take the opposite stance of Eich's — even though semicolons are canonically there at the end of statements, you're encouraged to omit them in your code.
Basically, I think you're taking a far stronger stance than is warranted. I don't agree with a lot of what Thomas Fuchs said in the OP, but let's not try to outdo him in absurdity. You can feel that including semicolons is the right choice without ignoring the plain fact that ASI does mean you can end statements with newlines most of the time (and that the inability to do so in a few edge cases does not prove otherwise).