News for hackers. Stuff that matters.
Re:Why are programmers afraid of not using semicolons in Jav... by jannes on Sunday August 07, 2011 @11:58AM (#2856870)
There are some caveats. This, for example, would not work as expected:

  foo()
  [1,2,3].forEach(bar)
Automatic semicolon insertion wouldn't work here, because the bracket could be a continuation of the last line. The same goes for parentheses at the beginning of a line.

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

Re:Why are programmers afraid of not using semicolons in Jav... by einaregilsson on Sunday August 07, 2011 @12:54PM (#2857038)
Yes, the two cases where I actually think I could run into that are that and var x = i (function() {...})()

where it wil think i( is a function call.

Re:Why are programmers afraid of not using semicolons in Jav... by sjs on Sunday August 07, 2011 @01:57PM (#2857237)
The informal and single easy rule is to prefix lines that begin with punctuation with a semi. In practice only [ and ( crop up, almost nobody begins lines with a prefix increment or decrement. If you use += 1 and -= 1 instead you sidestep that case.
Re:Why are programmers afraid of not using semicolons in Jav... by felipemnoa on Sunday August 07, 2011 @02:02PM (#2857252)
Or, you could just add a semicolon. KISS at work.
Re:Why are programmers afraid of not using semicolons in Jav... by einaregilsson on Sunday August 07, 2011 @02:27PM (#2857329)
Yes, you could just add a semicolon in front of lines that start with punctuation (tiny percentage of all lines) or you could just stick them at the end of every single line...
Re:Why are programmers afraid of not using semicolons in Jav... by eropple on Sunday August 07, 2011 @02:32PM (#2857348)
Yes, you could put them at the end of every statement. Because consistency is a good thing.
Re:Why are programmers afraid of not using semicolons in Jav... by einaregilsson on Sunday August 07, 2011 @02:41PM (#2857374)
@eropple: So you put semicolons after every line? Even after block statements {} ? Why not, if the goal is to be consistent?
Re:Why are programmers afraid of not using semicolons in Jav... by burgerbrain on Sunday August 07, 2011 @03:32PM (#2857506)
You should use the reply button.
Re:Why are programmers afraid of not using semicolons in Jav... by einaregilsson on Sunday August 07, 2011 @04:39PM (#2857666)
It wasn't visible for me on that one comment. I don't know why, I thought it was too deply nested or something, but now I see it. Weird.
Re:Why are programmers afraid of not using semicolons in Jav... by sjs on Monday August 08, 2011 @12:56AM (#2858847)
The Reply link doesn't show up for a minute or two. I guess it's supposed to force you to think instead of firing off a hasty response. Kind of pointless for one liners but hey...
Re:Why are programmers afraid of not using semicolons in Jav... by sjs on Sunday August 07, 2011 @02:06PM (#2857267)
That's perfectly fine as long as you're honest about why you do it. Most people here are misinformed.