Live data from Hacker News

Poll: Semicolons in JavaScript

news.ycombinator.com

1–10 of 44 posts

Poll: Semicolons in JavaScript

#1
Question: Should people always use semicolons in Javascript?

For those unfamiliar with the matter, Javascript allows semicolons to be omitted sometimes, see:

http://inimino.org/~inimino/blog/javascript_semicolons

Update: This poll was started as a result of a discussion on the node.js mailing list:

http://groups.google.com/group/nodejs/browse_thread/thread/35810f231cb289aa

Re: Poll: Semicolons in JavaScript

#3
For me it's a 'yes' based on the simple rule that explicit is always better than implicit. That sort of 'optimisation' seems to be really cool when you're just starting out in a language but in the long run it isn't worth it.

The first time you're bitten in the behind by a subtle bug after a couple of hours searching you've given up a hundredfold the time you have saved up to that point by not having to type those ;s. At that point people usually 'get it'.

Re: Poll: Semicolons in JavaScript

#7
post #2

Personally I think the Google Javascript Style Guide has it right: > Relying on implicit insertion can cause subtle, hard to debug problems. Don't do it. You're better than that. http://google-styleguide.googlecode.com/svn/trunk/javascript...

Interesting that you use Google as the example for always using semi-colons with JavaScript. When writing a code-example on a white-board during my Google interview, I was using semi-colons throughout my code. One of the things the interviewer asked was why I was using semi-colons ... implying that my code wasn't as clean as it could be. We talked about whether they were needed or not, but his preference seemed to be that they weren't really necessary, and that I shouldn't have been including them in my code.

I continue to use them in my code.

Re: Poll: Semicolons in JavaScript

#9
post #5

When the curly-braces-syntax is replaced with proper sexp, I'm all for it. Until then, I prefer to keep the semicolons.

Parenscript; the happy amalgamation of Common Lisp and JavaScript, in your server or your browser.

http://common-lisp.net/project/parenscript/

People are writing Node.js code in it :-)

http://tryparenscript.com/

It reminds me of an old Scheme dialect, implemented in Common Lisp, and was used to implement the Yale Haskell compiler (by Sandra Loosemore[1], et al.); it's just one of those baroque language towers that you're not sure how it works, but somehow works perfectly.

Combine parenscript with CSS-Lite[2] and you enter a weird world of web development in 100% Lisp (not entirely good though; you wont be able to cut-and-paste stuff from SO, but then, thinking for yourself might not be such a bad thing after all :-)

--

[1] Yes, that Loosmore; Ms GNU libc herself, along with being an OG GNU hacker, right from the start and an RMS buddy, she was also an editor of the CL spec.

[2] http://www.cliki.net/css-lite

Re: Poll: Semicolons in JavaScript

#10
post #6

JS minimizers tend to remove all the newlines, so semicolons are often necessary if you use one.

Was going to say that this is clearly a bug in the minifier but then I thought about the effort involved in properly supporting non-terminated lines (or even detecting it). You're going to end up writing a JS parser.

This really shows the cost of this syntactic nicety to the language.

Post reply on HN