7 ms·
Imagine still using semi-colons in JS source in 2020 and "bookmarklet compatibility" being your reasoning.
by slimed 7y ago
Imagine still using semi-colons in JS source in 2020 and "bookmarklet compatibility" being your reasoning.
- jarfil 7y agoSemicolons in JS is how you differentiate between someone who understands that code ambiguity leads to pain, vs someone who shouldn't be allowed near multi-line statements.
- pretty_lorelei 7y agoHonest question: how often does the code ambiguity due to lack of semicolons lead to non-obvious bugs? I'm nowhere close to being a JS expert, but I've done some JavaScript-heavy pet projects and I've got an ambiguous statement interpreted wrong exactly once, and the cause was pretty obvious within a minute of looking at the error.
- z3t4 7y agoIf you accidently write a comma instead of semicolon it can have interesting effects.
- fenomas 7y agoIn my experience, precisely as often as you write statements that start with a left bracket or paren. E.g. [1, 2, 3].forEach( ... ) (function(){ ... })() Statements like that are virtually always errors under ASI, but if you avoid them nothing else causes problems.
- DonHopkins 7y agoIt's not so much how often it happens, but how freaking hard it is to find the problem by inspection when it does happen.
- fenomas 7y agoLinters correctly highlight all the ASI-related that realistically happen. (Or eslint does anyway, can't speak for others.)
- DonHopkins 7y agoGood linters correctly highlight all missing semicolons as a symptom of sloppy, negligent, careless programming (or pointless syntactic showboating). It's also technically syntactically valid to omit braces around single statements after if, else, for, and while statements, but idiotic and dangerous to do that, too. https://wiki.c2.com/?FixBrokenWindows https://wiki.c2.com/?FixBrokenWindows https://www.rtuin.nl/2012/08/software-development-and-the-broken-windows-theory/ https://www.rtuin.nl/2012/08/software-development-and-the-br... https://blog.codinghorror.com/the-broken-window-theory/ https://blog.codinghorror.com/the-broken-window-theory/ https://medium.com/@matryer/broken-windows-theory-why-code-quality-and-simplistic-design-are-non-negotiable-e37f8ce23dab https://medium.com/@matryer/broken-windows-theory-why-code-q...
- slimed 7y agoPlease give a concrete example of this pain that you have actually experienced. I understand that ASI (automatic semi-colon insertion) is in theory ambiguous because you are relying on the compiler, or in some cases many different compilers, to execute the statement correctly. In practice, for over a decade, I have never run into such an issue. I suspect it's due to engineers trying to get too cute with their implementations.
- z3t4 7y agoif(foo) doX() doY()
- slimed 7y agoFor the benefit of the rest of us, can you explain what issues this causes and where/how you are running this code?
- NoInputSignal 7y agoIntuitively this becomes: if(foo) doX() doY(); Intuitively, as a someone who uses C style languages, this becomes: if(foo) doX(); doY(); Can someone confirm which intuition is correct? I ask because, to me: it not being intuitive is a problem--even if it is not classified as ambiguous. It being only contextually intuitive, also seems somewhat problematic--but maybe excusable if it is assumed you know some similar language going into it and it behaves similarly to that other language.
- fenomas 7y agoNo idea what GP was trying to say, but the C style intuition is correct. The bug in that code is due to omitted brackets, it has nothing to do with semicolons/ASI.
- z3t4 7y agoMy point was that its hard to tell where the semicolon will be inserted. As well as the intention of the programmer. Here is another example: if(x) return "foo" return callback (1,2,3,4)
- detaro 7y agoImagine not understanding why bookmarklet compatibility is cool for something like this and putting people down for it with a cheap "it's 2020" meme.
- slimed 7y agoA bash one-liner solves this problem for you. If you think it's "cool" to execute JS as a bookmarklet you are free to distribute your own version of the library. The original commenter was the one "putting people down" by demanding the author do it "the right way".
- deleted 7y ago[deleted]
- wwweston 7y agoBookmarklets are situationally pretty useful; they’re the easy entry to custom cross-site userscripting, a test drive before going full extension. They’re as legit a use of JS as anything else is. (That said: if you use someone else’s code, putting up with their style is part of the bargain, even if I think leaving out semicolons is pointless aesthetic bikeshedding.)
- hombre_fatal 7y ago> even if I think leaving out semicolons is pointless aesthetic bikeshedding Bikeshedding isn't when you paint the bikeshed your favorite color, it's the bickering over the shade it should be painted which is actually what you did, especially since the damage has already been done. ;) This whole thread is insufferable bikeshedding.