Poll: Semicolons in JavaScript
11–20 of 44 posts
Re: Poll: Semicolons in JavaScript
#12Re: Poll: Semicolons in JavaScript
#13JS 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.
Re: Poll: Semicolons in JavaScript
#14Personally 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…
Re: Poll: Semicolons in JavaScript
#15Re: Poll: Semicolons in JavaScript
#16 var bla = function() {
//stuff
//more stuff
//some more
}//no semicolonRe: Poll: Semicolons in JavaScript
#17For 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…
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. However, I cannot see where there is any 'optimisation' in using linebreaks instead of semicolons. You better need to explain why someone should use both linebreaks _and_ semicolons, when only using linebreaks is actually as good as well.
Basically, it's just a matter of style. Aside from a few exceptions (e.g. described in http://inimino.org/~inimino/blog/javascript_semicolons), linebreaks terminate a statement. If you stick with writing only one statement per line, I don't see what's so implicit with it. Rather terminating a statement both with a line break and a semicolon is a tautology, and hence introduces unnecessary redundancy.
The actual question is, whether one can require that developers know the (maybe a handful) exceptions where a line break doesn't terminate a statement. I have decided (for myself) that I can require that knowledge, as it really comes down to only a few exceptions (that I believe are easy to remember).
But, of course, I'm aware that one can also come do another reasonable conclusion.
The only important thing is that people make a concious decision about the issue at all. The importance of this increases with the number of people that are working together on a particular project.
Here a link to another article discussing that issue: http://mislav.uniqpath.com/2010/05/semicolons/
Re: Poll: Semicolons in JavaScript
#18Earlier quoted context omitted.
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…
Perhaps your interviewer asked the question to see if you could justify them, thus gauging your understanding of how the language is parsed at runtime. The fact that the conversation continued may indicate that he or she wasn't convinced by your answer?
Re: Poll: Semicolons in JavaScript
#19When I was a young journeyman programmer, I would learn about every feature of the languages I was using, and I would attempt to use all of those features when I wrote. I suppose it was a way of showing off ...
Eventually I figured out that some of those features were more trouble than they were worth. Some of them were poorly specified, and so were more likely to cause portability problems. Some resulted in code that was difficult to read or modify. Some induced me to write in a manner that was too tricky and error-prone. And some of those features were design errors. Sometimes language designers make mistakes.
Most programming languages contain good parts and bad parts. I discovered that I could be a better programmer by using only the good parts and avoiding the bad parts. After all, how can you build something good out of bad parts?
Re: Poll: Semicolons in JavaScript
#20Earlier quoted context omitted.
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…
Perhaps your interviewer asked the question to see if you could justify them, thus gauging your understanding of how the language is parsed at runtime. The fact that the conversation continued may indicate that he or she wasn't convinced by your answer?