Nobody argues it isn't valid to omit semicolons. People recommend against it because it is a mind-blowingly braindead language "feature" that should not exist in the first place, and can cause confusing errors and other problems.
Fuzzy ambiguous syntax may have a place in content (e.g. markup), but it sure as hell has no place in programming language syntax. The tragedy of Javascript is that underneath the awful veneer is a pretty elegant language...
If you prefix ( and [ with semicolons you're good to go. Nowhere else are they needed, and the problems with ASI aren't solved by using semicolons everywhere.
e.g.
function foo() {
return
{
something: 'here'
}
}
Using semis everywhere doesn't save you from ASI, you just have to be careful about line breaks. Whether you use semis or not. The problem isn't omitting semicolons, it's inserting spurious newlines. Keep braces on the same line as returns or wrap the returned expression in parens, return (....
You have to know the rules either way. It doesn't matter whether or not you use them, it's purely a style thing. Either way we shouldn't try to make anyone else conform to our preferred style unless they're contribution to a project.
edit: Downvotes but no rebuttals. If you ask me that's pretty telling.
ASI isn't going anywhere, we are stuck with it. I don't care if people use semis or not, but rallying for one side or the other is silly. This subject has been discussed to death on the Node mailing list, in blogs, on IRC and twitter many times over. Unless there are new arguments on either side there's no real point discussing this.
People who don't really understand ASI need to stop spreading FUD on the issue. Make no mistake, claiming that always using semis is going to "save you from ASI" is pointless. It does nothing to educate people on the real pitfalls of ASI and essentially is nothing but FUD.
Examples where lacking semicolons can cause problems are well-known and used by those who disagree with you. You are beating on a straw man anyway, nobody claims that using semicolons is going to solve all the related problems - but it solves some.
Can you provide an example where using explicit semicolons causes problems but omitting them does not?
Examples where lacking semicolons can cause problems are well-known and used by those who disagree with you.
Besides lines beginning with ( and [ I bet you cannot name one. Because that's the only one.
I don't have to provide examples where using semis causes problems because I never made that claim. That would be a ridiculous claim.
edit: I can't believe I'm getting sucked back into this. Go ahead and spread your misinformation then, I can't reason someone out of an idea that they weren't reasoned into.
Fear mongering about ASI is bullshit. It's not a "weird personal obsession" about semicolons, it's a "weird personal obsession" with the truth. If you tried to tell me that dinosaurs lived on Earth 6000 years ago I'd react the same way.
I'd also like to point out that I've mentioned the single case where you need semicolons, and nobody has been able to identify any others (because there aren't any). I'm not the one hand-waving here.
18
u/drobilla Feb 06 '11
Nobody argues it isn't valid to omit semicolons. People recommend against it because it is a mind-blowingly braindead language "feature" that should not exist in the first place, and can cause confusing errors and other problems.
Fuzzy ambiguous syntax may have a place in content (e.g. markup), but it sure as hell has no place in programming language syntax. The tragedy of Javascript is that underneath the awful veneer is a pretty elegant language...