by kolme · 10y ago · 0 comments
Let's see what Brendan Eich has to say about this:
> My two cents: be careful not to use ASI as if it gave JS significant newlines. [1]
and
> ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble.
Calling it "standard JS" struck me as pretentious at first. But calling it "standard JS" and calling for not using semicolons is absolutely delusional.
Let me be clear here:
- ASI (Automatic semicolon insertion) is a correction mechanism, designed to prevent silly errors, thus making the language "friendly".
- ASI does not work in many cases, where you do need a semicolon. So much for consistency!
All the rest of things in that list are just a matter of personal preference, but not the semicolons though. That's just plain wrong. And if people begin using this "standard" the bugs will come to bite them.
An Open Letter to JavaScript Leaders Regarding Semicolons http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...
JavaScript Semicolon Insertion – Everything you need to know http://inimino.org/~inimino/blog/javascript_semicolons
Are Semicolons Necessary in JavaScript? https://www.youtube.com/watch?v=gsfbh17Ax9I
Spreading FUD doesn't help anyone out.
The issue is not whether or not one individual can learn to use dangerous feature X. If you are writing code by yourself for your own use, you can use nested eval's and no semicolons with a little bit of `with` here and there, nothing wrong with that. However when you are writing code that is supposed to be developed by people other than you, you might want to write less clever code.
I could write code without semicolons, however that would mean that I would have to constantly keep an eye out for that case where I absolutely need to add it to prevent ASI from doing the wrong thing. It takes probably 100ms to hit that semicolon key, however it takes a lot more time to debug code without semicolons.
If you hat semicolons with a passion for some reason, you could use Coffee Script or some other language which was designed without semicolons and has clear semantics around it.
Particularly interesting too in the article linked is the link to the paren-free strawman proposal [1] that suggests maybe its past time that JS also drop the algol-family heritage require parentheses in the head of for/while/if for whitespace sensitivity instead (ala CoffeeScript, golang).
> i have learned to use them, that's why there isn't one present.
Did you, really? Because that's how that bug came to be. Because of you stubbornly omitting them.
Why do these people want to avoid semicolons at all costs? Even inconsistencies? Even potential bugs? Why?? I just don't get it.
I need to leave this discussion, I'm getting nerd-rage.
https://github.com/brave/browser-laptop/blob/master/package....
^ Brendan's own company (Brave) uses `standard`, so it's clear he doesn't think omitting semicolons is so bad.
Now I have 4 extra rules to remember and destructuring, amongst other things, will look like shit. And for what gain? If there was an actual gain to leaving out the semicolons, I'd be onboard but the only gain here is someone's aesthetic pleasure and someone else's aesthetic displeasure. Last time I checked, code was there to do things, not look pretty. Making the former more difficult to achieve the latter is not only stupid, it's impossible because now you're pandering to fashion which varies from person to person. Also, it's bikeshedding. As if Javascript didn't have real problems it needs solved.
95% of the time I ever use a winky frown is Typescript type assertions ;(<any>someObj)...
It doesn't impact destructuring at all because destructuring lines start with let (or const, or maybe var if you are feeling old school that day).
ASI is not very different at all from the newline rules in Python, ML, Haskell, et al... Freedom from semicolons makes ES2015 feel like the OCaml derivative it always sort of has been.
That's just not true. You can have destructuring assignments, not just declarations: `[a, b] = [b, a];` is perfectly legal ES2015.
;[a, b] = [b, a] ;[1, 2, 3].forEach(bar)
To my eye, having that in my code looks far worse than just using "standard" (ha ha) semicolons.You mention a for loop exception as well. I don't understand what that exception is, but the general message seems to be "Trust me, you can totally omit semicolons! Everything is ok! Except for all these weird edge cases, but you can just hack kludges around them!"
Yes, people like to bring up these goofball edge cases that don't actually happen in real life. Tell me, when was the last time you mapped over an array literal?
I'm serious, it has been years now, it is ok not to use semicolons in Javascript. People just need to... unclench. It is ok not to use them. I don't know what hellfire and brimstone people expect to happen when they stop using semicolons but it isn't going to happen.
The for-loop thing is that semicolons are required to delimit the initialization, condition, and increment of a for-loop. So you use them there.
See, this is the thing - not using semicolons to terminate statements is nicer than using them (pure opinion of course), and it doesn't cause problems in practice. But it would be ridiculous to take some hard-line stance of "absolute zero semicolons ever". The point is not that we hate the semicolon glyph or something, the point is that you don't need them to terminate statements, so we don't.
(function(a1, a2) {
// something
})(arg1, arg2); let sql = `delete from order_lines`
` where order_id = ${orderId}`;
Without a lint complaining about a missing semicolon you wouldn't notice this bug.This has happened to me with a rather more complex query.