7 ms·
Is there any particular reason why you refuse to put in the semicolons in Javascript?
by YuriNiyazov 15y ago
Is there any particular reason why you refuse to put in the semicolons in Javascript?
- jpeterson 15y agoThere's a whole hipster movement going on right now around the idea of omitting semicolons from JavaScript code. I believe CoffeeScript is the culprit. Personally, I agree with Crockford -- it's dumb.
- leetrout 15y agoMeh, the real hipsters are just pushing comma-first.
- maratd 15y agoThey're all hipsters.
- deleted 15y ago[deleted]
- bratsche 15y agoKind of funny that you say this, since CoffeeScript inserts semicolons. The lack of semicolons is the one major thing in the Github style guide that I think is stupid. It seems silly to avoid using semicolons in Javascript because it actually takes a little bit more effort than just using them.
- Osiris 15y agoOn my team we've decided to use semi-colons in JavaScript for this exact reason: It would actually take more effort to stop using them as our other major language is PHP. More effort for no benefit is pointless.
- chime 15y ago> I believe CoffeeScript is the culprit. CoffeeScript removes semicolons from CoffeeScript, not JavaScript.
- deleted 15y ago[deleted]
- groovy2shoes 15y agoBecause standard-compliant JavaScript implementations don't require them (ECMAScript describes a model of "semicolon insertion" that implementors are supposed to follow).
- underwater 15y agoNot required doesn't necessarily mean it's a good idea. If they were never needed I'd understand, but sometimes they are. I don't see the point in forcing the developer to make a conscious decision on whether to include a semicolon. Omitting semicolons also means that the correctness of a line of code is determined by the unrelated lines that follow.
- groovy2shoes 15y agoWhile the virtues of semicolon insertion are highly debatable, developers are permitted by the ECMAScript standard to write code that relies on it. A tool like JSMin should be aware of semicolon insertion. ricardobeat put it very well elsewhere in this thread: "It is a bug on JSMin. Minifying should never alter code behaviour."
- ars 15y agoActually JSMin is aware of semicolon insertion and handles it correctly. They just disagree on whether a semicolon gets inserted here.
- groovy2shoes 15y agoUnfortunately for JSMin, browsers attempt to implement at least the ECMAScript specification, not just "the good parts."
- deleted 15y ago[deleted]
- ricardobeat 15y agohttp://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...
- drivebyacct2 15y agoLike I said, there are many, many libraries that don't use them. I used to prefer having semicolons in my javascript, then I started writing a bunch of Go. Now I wind up forgetting sometimes, though some part of me likes it, and so I continue using semicolons in my javascript. That having been said, I think it's a matter of personal opinion (likely just what a given person is used to), and if it fits with the spec and the common usage, then you'd think a library that is expected to work with/on other libraries would try to be accommodating. edit: To further clarify, Javascript's stance is silly, because you need to know how semicolon insertion works. It's extra knowledge you have to have. Thus, I think I agree with most here that it's easier to just use them. (Other languages have optional semicolons but they don't change the meaning of the syntax at all.) edit2: This is GitHub, why is there not a fork already with this issue behind us?
- sjwright 15y agoHey everyone, I've just learned to drive without wearing a seatbelt. It's possible! The laws of physics allow it!
- prodigal_erik 15y agoDriving without a seatbelt would be perfectly reasonable if I had a written list of all possible accidents to drive around. The twist here is that the one and only grammar change that could break this code may actually happen soon. Until then, though, the code is valid and Crockford is intentionally leaving a bug in jsmin.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]
- hhhhhhhhh 15y agoin vim pressing A lets me change things at the end of the line, and semicolons get in the way of that