7 ms·
Honest 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 som
by pretty_lorelei 7y ago
Honest 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...