Live data from Hacker News

Brendan Eich: The infernal semicolon

brendaneich.com

61–70 of 143 posts

Re: Brendan Eich: The infernal semicolon

#61

Earlier quoted context omitted.

No, there's an important distinction. ASI does not even kick in without a syntax error. Yet the "expectation of ASI" or (I think more likely) "expectation of newline significance" makes people believe that they'll get a ; inserted by separating two things by one or more newlines. Most languages do not specify error correction. HTML5 of course does; CSS too; among general programming languages it's much less common. T…

I suppose I'm thinking of that as implementation details; from the perspective of languages, it appears ECMA-262 does specify a well-defined language. Any input string is either rejected (not in the language at all), or is mapped unambiguously to an abstract syntax tree. So from that perspective, any sequence of characters that gets you an abstract syntax tree is a program in the language! How precisely it gets mappe…

Yes, ECMA-262 completely specifies (modulo bugs) sentences that are accepted or rejected, and for those accepted, their meanings.

But that doesn't alter ASI's error-correction nature, which is not an "implementation detail" -- it's in the spec and all too observable.

You're right, it has the character of a warning system, like Dart's unsound "types". But if it had been noisy (consoles in the early days were costly), too many developers would have ignored the warnings, and users would have paid for the overhead.

Your concluding sentence is spot on, I agree people should use semicolons in JS. Relying on a Ruby-like coding style in the large is way too risky.

Re: Brendan Eich: The infernal semicolon

#62
post #47
post #42

Is it me, or did the author tack on a new topic regarding the use of && and ||? The fact that they return the controlling operand is quite useful. Consider a situation where you want to check the property of an object, but don't know if that object is null: var foo = obj && obj.bar; I find this much more readable than: var foo = null; if (obj) { foo = obj.bar; } You can accomplish the same thing with a ternary operat…

I can't speak for Brendan, but I generally think && / || are great for assignment , but otherwise it's code-smell. var foo = obj && obj.bar; // great !isActive && $parent.toggleClass('open'); // smelly if (!isActive) $parent.toggleClass('open'); // better

I believe HTML5 boilerplate implements the smelly pattern.

https://github.com/h5bp/html5-boilerplate/blob/master/index....

Re: Brendan Eich: The infernal semicolon

#63
post #33

Heh, I was waiting for this post. Coming in the next 24 hours: - "Why I use minimal semi-colons in Javascript" - "ASI is broken but I like it" Honestly I'm shocked at the defense of this practice (of ASI "abusage"). It speaks loudly to Jacob's (fat@githib) ranking of ego-stroking and showboating over creating readable code, particularly for a library "Designed for everyone, everywhere" [1]. I'm confounded that such a…

I really don't understand how a particular usage of semicolons and logical operators is indicative of ego-stroking, showboating, and "hipster", as if the word hipster even means anything at all. If fat _said_ something to make you use those words then that would make sense, but as it is I'm very confused.

Re: Brendan Eich: The infernal semicolon

#64

The eternal fires of high level bike shedding: semi-colons, whitespace and curly braces, no programming discussion or language can escape all three. Be liberal in what you accept and conservative in what you send (i.e. just use semi-colons) and your systems will work and play well with others being interoperable.

well JavaScript was liberal in accepting statements separated by newlines and look what happened

Re: Brendan Eich: The infernal semicolon

#65
post #60
post #33

Heh, I was waiting for this post. Coming in the next 24 hours: - "Why I use minimal semi-colons in Javascript" - "ASI is broken but I like it" Honestly I'm shocked at the defense of this practice (of ASI "abusage"). It speaks loudly to Jacob's (fat@githib) ranking of ego-stroking and showboating over creating readable code, particularly for a library "Designed for everyone, everywhere" [1]. I'm confounded that such a…

I'm surprised no one has made a little command line tool that follows the rules and automatically inserts semicolons according to the ASI spec. That might even be useful.

...or perhaps a simple "Zen of Javascript" would be in order.

Reading this "debate" makes me thankful for the Python Community and their stance on "readable code" above all else.

Re: Brendan Eich: The infernal semicolon

#66
post #16

Earlier quoted context omitted.

You haven't been around for long enough or just aren'y cynical enough, I went to bed knowing that there would be at least 5 more posts about it in the morning

Yeah, standard procedure is 1. "X is stupid" post 2. "But I like X" posts

    3. "X is stupid, but I like it anyway!"

Re: Brendan Eich: The infernal semicolon

#67
post #38

The key point: "ASI [“Automatic Semicolon Insertion”] is an error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble."—Brendan Eich

I think the other thing that goes unmentioned is that a single semi-colon on a line in a file would pretty much end this debate. Perhaps I've worked too much in teams, but surely "path of least resistance" has to factor some , right? I mean, if the choice is add a semi-colon to a line in a file versus asking somebody else to rewrite the compiler to be able to accept it, surely common sense would just be to add the se…

Even if we inserted the semicolon, JSMin would still be broken :)

Re: Brendan Eich: The infernal semicolon

#69

Earlier quoted context omitted.

Yes, he's acknowledged many times (including in this post) that it was a mistake. That was the intention, but it wasn't successful. It should have gone all in (no semicolons at all) or not have existed.

I think it was a reasonable decision at the time. The idea was that JavaScript was not going to be some language people wrote hundreds of thousands of lines of code in, and that the target audience would become frustrated if the language didn't "help" them. For example, if JavaScript truly were to always require semicolons at the end of lines then that means this would be a syntax error: ... > Error, missing semicolo…

[deleted]

Re: Brendan Eich: The infernal semicolon

#70
post #13

if ; (x3B?) and \n (x0A) are the same size, why use ; in minified JS if \n has more "features"

On the input side, I would guess the problem is that the minifier in question uses a parse tree with a not-quite-perfect grammar. It sees

    clearMenus()
    !isActive && $parent.toggleClass('open')
and parses it the same way it would have done

      clearMenus() !isActive && $parent.toggleClass('open')
On the output side, using ; is simpler to program (A\nB only means A;B in some cases, depending on B). And you'll receive fewer flames for it.
Post reply on HN