9 ms·
No semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as
by kolme 10y ago
No semicolons? REALLY? We've already spoke about this, people.
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.
[1] https://brendaneich.com/2012/04/the-infernal-semicolon/ https://brendaneich.com/2012/04/the-infernal-semicolon/
- feross 10y agoI recommend reading the following articles before you assume that omitting semicolons is dangerous. An Open Letter to JavaScript Leaders Regarding Semicolons http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding 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 http://inimino.org/~inimino/blog/javascript_semicolons Are Semicolons Necessary in JavaScript? https://www.youtube.com/watch?v=gsfbh17Ax9I https://www.youtube.com/watch?v=gsfbh17Ax9I Spreading FUD doesn't help anyone out.
- voidr 10y agoI know I can write a working JS application without semicolons, however I can also write a working JS application where with `eval` and `with`. 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.
- feross 10y agoYes, let's see what Brendan Eich has to say about this. https://github.com/brave/browser-laptop/blob/master/package.json#L124 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.
- spdionis 10y agoThis is the modern version of tabs vs spaces.
- joesmo 10y agoTotally agree. It then leads to this stupidity: "Never start a line with (, [, or `." https://github.com/feross/standard/blob/master/RULES.md#semicolons https://github.com/feross/standard/blob/master/RULES.md#semi... 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.
- WorldMaker 10y agoIt's one "extra" rule. I call it the "Winky Frown Rule" or you could less cheekily refer to it as something of a "Complete Emoji Rule": lines that start with frowns (, [, ` should be winky frowns: ;(, ;[, ;` 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.
- bakkoting 10y ago> It doesn't impact destructuring at all because destructuring lines start with let That's just not true. You can have destructuring assignments, not just declarations: `[a, b] = [b, a];` is perfectly legal ES2015.
- WorldMaker 10y agoFair enough, not a use case I'd encountered a need for in my code, yet. Still not that "ugly" from a winky frown perspective: ;[a, b] = [b, a]
- lobo_tuerto 10y agoCrockford on Bootstrap's semicolon omission: “insanely stupid code” https://news.ycombinator.com/item?id=3842713 https://news.ycombinator.com/item?id=3842713
- kolme 10y agoThe answer from @fat is face-palm worthy: > 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.
- rasapetter 10y agohttps://github.com/Flet/semistandard https://github.com/Flet/semistandard
- draw_down 10y agoEverything will be fine if you don't use semicolons. My team and I haven't, for years now. It's really, really, truly honestly ok. I promise. (Only exception is for-loops)
- Zecc 10y agolet 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.
- recursive 10y agoAccording to the link, you have resort to this kind of weirdness in order to reliably omit semicolons. ;[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!"
- emodendroket 10y agoI assume it's that you have to separate the three parts of the for loop arguments with semicolons
- draw_down 10y ago(Apologies for the delay, I had to wait to respond since the lovely people in this discussion have downvoted me) 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.
- WorldMaker 10y agoI think the keyword in Brendan Eich's article is maybe "be careful" rather than "don't use". Overall, Brendan Eich is mostly positive on ASI (otherwise the language wouldn't have it) and some of the article is about how if things had been left to cook longer it's just as likely JS would be a more newline-sensitive language than it is. 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). [1] https://brendaneich.com/2010/11/paren-free/ https://brendaneich.com/2010/11/paren-free/