r/javascript • • Feb 05 '11

Are Semicolons Necessary in JavaScript?

http://aresemicolonsnecessaryinjavascript.com/
0 Upvotes

66 comments sorted by

View all comments

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

-2

u/sjs Feb 06 '11 edited Feb 06 '11

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 (....

http://inimino.org/~inimino/blog/javascript_semicolons

http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding

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.

4

u/plantian Feb 06 '11

I think you're missing the point here. ASI/Semicolons are not the problem. Here is the problem: "Either way we shouldn't try to make anyone else conform to our preferred style unless they're contributing[contribution] to a project."

This kind of shit just wastes everyone's time because every project then spends hours debating the same shit when each member did something different in the last project. Personally I don't find the location of semicolons in my code a way of expressing myself. The debate on the node list, irc and twitter that you mention is case in point. This is the kind of shit that REAL leadership would eliminate. Crockford almost was able to get everyone together but apparently he failed because it says all over his site to just use semicolons and a lot of other things that people don't follow because they want to express themselves with fancy semicolon placement, dropping braces and pushing around whitespace. If you like JavaScript then you're only hurting its progress with this shit. Right now we could be talking about how to improve modularization of JavaScript, improve sharing of JS between frameworks or even handle future integration of new features but instead we are all talking about total bullshit. I think the phrase is "can't see the forest for the trees".

Take one for the team and always use semicolons. The problem has already been solved: http://javascript.crockford.com/code.html

Now, let's go write some libraries, plugins and apps!

1

u/sjs Feb 06 '11

This kind of shit just wastes everyone's time because every project then spends hours debating the same shit when each member did something different in the last project.

There's no debate. Founders of a project choose the style and contributors conform. It's just polite.

Anyway we're in total agreement.

1

u/plantian Feb 08 '11

I can't tell if you are baiting me or not here but sadly I go for both synthetic and live bait.

I don't think we are quite in agreement. I'm saying that ALL JavaScript developers should strive to all follow the EXACT same conventions not just whatever that project founder feels like. Founders can have styles for whatever higher level patterns they want but letting project founders all make up their own low level coding conventions just creates fragmentation. I hate this stupid website because all it does is open this crap up for debate for every founder rather than just letting the JS community globally finally agree on one damn thing. The tone of this discussion is a good sign though that people are finally coming together behind something. It gives me hope. Its small but everything has to start somewhere. The JavaScript community, as represented in this discussion, is waiting for you to get on board.

1

u/sjs Feb 08 '11

I'm not trolling. And we're not quite in agreement. I appreciate your point of view but I don't think it's realistic.

I'm saying that ALL JavaScript developers should strive to all follow the EXACT same conventions not just whatever that project founder feels like.

That would be great, but without a BFDL to mandate 4 spaces or whatever like Guido can do for Python that is just a pipe dream.

Some people indent with 2 spaces, some with 4, some with tabs. Some like hanging braces and some don't, some like spaces around operators and some don't. Some like spaces between keywords and conditions, some don't. The semicolon thing is a non-issue in comparison! Generally people use them and that's that.

I personally don't use them in my JS unless it's an open-source library that I want others to use. I make a pragmatic decision to include them because some will turn up their nose if they don't see any semis. It's ridiculous, but I do it anyway because people don't understand the issue and when people don't see semis they get uncomfortable because they don't understand the rules about when they're necessary.

It's easy to tell them the rules, but their minds have been tainted by all the misinformation out there. I'm trying to put a stop to the misinformation but everyone here is putting their fingers in their ears and going "LA LA LA!" ... which is why I've given up trying to reason with them.