4 ms·
After reading this, I just want to say that I do not think semicolon-less javascript is, in general, a good idea. Development projects are almost always team e
by dos1 15y ago
After reading this, I just want to say that I do not think semicolon-less javascript is, in general, a good idea.
Development projects are almost always team efforts. And, unfortunately, there's almost always one or two team members who aren't very good. Some of you folks that only work on startups with brilliant people might disagree, but in my experience most development teams have some bad apples who have let their tech skills rot, or won't try for some reason or another.
These people are going to have a tremendous time just writing halfway competent javascript (especially since it's probably not similar to their OOP language of choice). Suggesting they write code in an uncommon way is just begging for trouble. Most of the examples on the internet use semicolons, as do most of the frameworks. In fact, I hope that members of my future teams never see this javascript style guide or even know that it's possible to omit semicolons in many cases.
I'm quite sure someday soon I'm going to hear this over the cube wall: "Hey, GitHub doesn't use semicolons in their javascript so I won't either!" And then I will be very, very sad.
- lucisferre 15y agoYeah, you save one character per line, and gain a lot more in cognitive friction. Words to live by: "don't make me think" even about whether or not I need a semi-colon here.
- secoif 15y agoDropped semicolons about 6 months ago and haven't had a problem even once. Once you get into the habit, it requires zero extra effort. You just know when to put them in, same way you just know when to use parens vs curlies. Coding with semis is like coding with parens around every expression; unnecessary and paranoid.
- alttag 15y ago> Coding with semis is like coding with parens around every expression; > unnecessary and paranoid. Unless, of course, one is using Scheme or some other Lisp variant.
- 54mf 15y agoGood thing it's a Javascript style guide, huh? ;)
- alttag 15y agoIt was the "unnecessary and paranoid" bit that really turned me off. Flaming everyone who doesn't use the same style wasn't warranted, IMNSHO. I responded with snark. I think in general the answer may be to use the style that mimics the other code in the application. Rubyists may prefer the newline endings; those using Java or PHP may find having the semi-colon more comfortable. Having less contextual switch between languages may be easier. Such a sweeping statement seemed a bit ridiculous. Choosing to interpret it in a broader context was intended to highlight my opinion of the original statement. EDIT: It's been fun watching the mod of the GP go up and down ... zero, back to one, then to zero ... over and over.
- secoif 15y agoIt's unnecessary because apps continue to work with little to no modification without semis, it's paranoid because all of the reasons people come up with for why semicolons are important (lint tools? minifiers? bugs?), are all non-problems if you spend a few minutes changing your habits.
- dos1 15y agoBut why? Why drop the semicolons? What is the benefit? If the net result is exactly the same, why try and be tricky? What is the point, other than you can do it. But there are many tricky things we can do with programming languages, but very few we should
- true_religion 15y agoHe never said the net result was the same. He said that there were no problems. No problems doesn't imply no benefits.
- viscanti 15y agoOn a team of a sufficient size, dropping semicolons hurts. Someone will be running a static analysis "lint" program in their editor, and it will always flag those missing semicolons. That certainly adds additional cognitive friction to those users, who constantly see the reminder to add the missing semicolon. I guess I've never understood the argument for omitting them. It seems like an unnecessary trick. Coding guidelines should enforce the simplest possible patterns and techniques.
- secoif 15y agoUnlikely the default lint options are going to suit all teams anyway. JSLint/JSHint can, and should be configured for your team's style.
- secoif 15y agoThe point is to reduce noise. JavaScript already has a lot of cruft going on with all its anonymous functions, parens and curlies… anything to reduce the signal to noise ratio is a step in the right direction.
- lucisferre 15y agoIf you really cared about that you would use coffee script. Dropping semicolons is such a triviality.
- julioc 15y agoThat's a good point, even the reference article states that, in some cases, a semicolon is necessary (in the begin of the line). If it's necessary reason about use it on some cases (and mistakes will happen), why not use it on every line? The guide doesn't have anything about brackets and spacing on function calls (maybe because it's dropping the language).
- keyle 15y agoI completely agree with you. I'm also unsure about imposing coffeescript - although I find it interesting - in an enterprise environment. I'd rather have nicely crafted and long winded javascript with convention followed, than half javascript and half coffeescript which will hurt people's brain at some stage. Eventually, that stuff bites you and productivity - all that for the fame of using a brand new language (no offence intended) in the enterprise world. Assuming code is meant to live on for 4-5 years at least here.
- kisielk 15y agoAnd even if your team is superstars now it doesn't mean it always will be. What happens a few years down the road when you now have a team 5 or 10 times the size with people of varying skillsets and areas of expertise. Now that guy with mostly Python or Ruby experience needs to make some changes to your JavaScript code with what little knowledge of the language they have. It's helpful to write things to be as idiomatic as possible in those cases.
- sojacques 15y agoWell, the same thing could be said about "that guy with mostly C, PHP or Java experience".
- kisielk 15y agoI wasn't singling out any particular languages, just giving an example. It's a lot easier to understand code in an unfamiliar language if it's written in an idiomatic fashion as opposed to using all sorts of tricks.