Live data from Hacker News

Poll: Semicolons in JavaScript

news.ycombinator.com

21–30 of 44 posts

Re: Poll: Semicolons in JavaScript

#21
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...

FWIW: I would like to not use semicolons in JS. But the current "push" for that is IMHO a mix of ruby/python home sickness and "Let's do this because we are smart enough to do it right.". Both are terrible influences on style in any language.

Re: Poll: Semicolons in JavaScript

#23
post #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 yo…

As a lisper, I am ashamed that I did not know what parenscript was. I am very happy that you were able to correct that for me.

Re: Poll: Semicolons in JavaScript

#24
It seems like semicolon insertion is an example of browsers being liberal acceptors of slop. Good that the rules are codified by ECMA, much like HTML5's error recovery parsing rules, but I wouldn't omit semicolons on purpose.

Re: Poll: Semicolons in JavaScript

#25
Readability is the single most important quality of a piece of code. Semicolons aid readability by eliminating ambiguity and ensuring that nobody ever has to spend even a second figuring out whether your code will do what it looks like it will do.

I add semicolons for the same reason I surround if blocks with braces, pad out blocks with whitespace, and avoid the ternary operator in all but the most trivial cases. If you ever find yourself dropped onto a line of my code by a debugger, chances are you'll be able to figure out exactly what's going on immediately.

At least that's the goal.

(more here: http://expatsoftware.com/articles/2007/06/getting-your-prior... )

Re: Poll: Semicolons in JavaScript

#27
post #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…

> 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. I don't really get what you call implicit when you terminate statements with semicolons instead of linebreaks... ... Ok, I get what you're hinting it: there are some (very) few exceptions. How…

But linebreaks don't terminate statements in javascript.

  x = y
  
  /* TODO: clean this up to make it more readable
   * and maybe add some semicolons
   */
   
  + 4
  
  
... is a single statement.

Re: Poll: Semicolons in JavaScript

#28

Earlier quoted context omitted.

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.

I would hope that minifiers use a JS parser!

I imagine much of the minification could be done using just a lexer rather than a full parser. I'm quite probably wrong though.

Re: Poll: Semicolons in JavaScript

#29
post #6

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

This just isn't true.

The YUI minifier, for example, works perfectly fine without semicolons in the original. Equally, the Google Closure Compiler does also.

If you're using a minifier that just removes new lines and suffers without semicolons, I think you should rethink your minifcation process.

Post reply on HN