Hacker News new | past | comments | ask | show | jobs | submit login

Missing semicolons have more pitfalls than just minifiers being naughty.

  return
  someExpression
will parse out as:

  return;
  someExpression;
and you have assumption of function call in

  x = y
  (z).whatever()
which parses out as

  x = y(z).whatever()
Nothing hint or lint wouldn't catch though. IMHO, you really need to be special to avoid explicitly writing out semicolons, but to each his own. I can maybe give it a point for unique style. :)



Only evil people put their return value on a second line...

Regardless:

http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...

Although to be fair:

http://benalman.com/news/2013/01/advice-javascript-semicolon...


Wow, I got schooled. Did not realize rule 4 about lines starting with array subscript brackets or function argument parens. (regardless of the line's intent of perhaps being an array literal or simply starting with an expression to be evaluated early)

The sad reality, taking the second link to its satirical conclusion, is that all JS should be written on one line, with semicolons between statements. No guessing about the effects of line breaks if there aren't any. "I say we take off and nuke the entire site from orbit - it's the only way to be sure." :-)


While I favor Ruby/Python syntax, I'm impartial about semicolons. There are bigger battles to fight! For example, heretics who use comma-first arrays.


How would semicolons have prevented the first of those misunderstandings?

-- Don't get me wrong, those are good cases to know what is going to happen. But I think you are making the case that semicolons provide a false security blanket, since the language can complete a line you meant to wrap, or, alas, merge 2 lines you meant to have separate.

I think shell (and a few other languages) actually got it right: 1 line = 1 statement, unless there is an explicit continuation.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: