5 ms·
The thing is, semicolons do make a difference with JavaScript. It's now 404ing, but there was a pretty well-known argument on one of Twitter Bootstrap's GitHub
by wldlyinaccurate 13y ago
The thing is, semicolons do make a difference with JavaScript.
It's now 404ing, but there was a pretty well-known argument on one of Twitter Bootstrap's GitHub issues[1]. The Bootstrap guys didn't use semicolons, and it caused problems when minifying the code. It's an edge case, I know, but it was a problem.
I never understood the whole anti-semicolon thing anyway. It just seems really hipster to me. Use CoffeeScript, if you don't want semicolons.
[1] https://github.com/twitter/bootstrap/issues/3057
- jalfresi 13y agoI've always equated javascript without semi-colons with missing comments and poor commit messages. It's just inconsiderate to other developers who have to read your code. I understand that it is a "feature" of javascript (misfeature in my opinion), but the point that "everyone else does it is not a good argument" is false. We've got like 15 years of javascript written with semicolons. Stop being an inconsiderate prick and just friggin write the code like everyone else! Don't be that guy (or gal). Comment your code. Write good commit messages. Use semicolons in your javascript.
- tg3 13y agoIf it caused problems when minifying the code, the problem was with the minifier not parsing correctly - a minifier shouldn't change the way the code is interpreted. I understand that using existing minifiers is a possible reason to use semicolons, but not using semicolons is not an inherent issue here.
- ealexhudson 13y agoIt shouldn't, they genuinely are optional, and Javascript coders need to know when they can be inserted because you can't turn that behaviour off. However, needing to understand the rules is one thing - I much prefer to see the semi-colons in there. I dislike seeing any formatting that is substantially different from the accepted norm and find it harms readability.
- marrs 13y agoWhy does it seem hipster to use a language feature? Is it hipster to use null coalesce as well? The article linked above explains the reasons to omit semi-colons very well. I would personally prefer if JS forced you to terminate all statements with a semi-colon to avoid any ambiguity, but there you go. Speaking of ambiguity caused by whitespace, Coffeescript is a 1st degree offender for this. All you have to do is indent the wrong block of code, and you completely change the scope of a nested function, and you have no visual indication of your mistake whatsoever.
- mradmin 13y agoIt's hipster because it goes against the accepted standard way of writing Javascript. See https://news.ycombinator.com/item?id=1547647&utm_source=twitterfeed&utm_medium=twitter https://news.ycombinator.com/item?id=1547647&utm_source=twit...
- marrs 13y agoMy interpretation of "hipster" is being different because you think it's cool to be different. Being different because you think it's a better approach is called "making progress", either because you'll be proven right or proven wrong. I've thought about the de-facto standard way a lot and I think that it does nothing to avoid bugs while potentially misleading a coder about the language. Therefore I think it's worse. The only reason I follow the de-facto standard is because the time spent arguing about it with my peers is better spent getting work done.
- andypants 13y agoNobody has any good reasons that apply to most people, both for and against semicolons. There really isn't a huge difference in either style except in rare cases. > The only reason I follow the de-facto standard is because the time spent arguing about it with my peers is better spent getting work done. Which is why that is an excellent reason. Standards are useful, so if there is one, stick to it. If there is no reason to go against the standard, then don't. > I think that it does nothing to avoid bugs while potentially misleading a coder about the language. Therefore I think it's worse. Not seeing any semicolons can also potentially mislead about the language. It is not worse, they are both misleading until you realise ASI exists. Omitting semicolons also does nothing to avoid bugs, and introduces a different (additional?) set of edge cases where bugs may appear.
- testing12341234 13y agoThe link to the issue you mention is broken because the bootstrap repository moved from twitter to twbs. The new link is https://github.com/twbs/bootstrap/issues/3057 https://github.com/twbs/bootstrap/issues/3057. Also note, that ultimately regardless of personal semicolon preference, this was an issue because of a parsing bug in JSMin. It was fixed in JSMin with this commit[0]. Other minifiers such as Closure and YUI did not exhibit any issues with the code as it had been written. [0] https://github.com/douglascrockford/JSMin/commit/5ca277ea452beae1c25db3bc0ef5c81309a3daf4 https://github.com/douglascrockford/JSMin/commit/5ca277ea452...