That is the first JS style guide where there isn't anything stupid in it and I actually agree with what it says. The closest thing to a disagreement is single quotes only for strings, and that is only because I tend to mix them up myself.
They even got var right which says less about them and more about the state of "JS culture". (I would have expected one var per line to be an obvious no brainer which didn't need to be stated.)
(I would have expected one var per line to be an obvious no brainer which didn't need to be stated.)
I don't get why people form such strong opinions about these things when software can automagically convert a list of variables into separate vars or convert one type of string quote into the other. Do what ever the hell you want and then convert your code to the team standard before commit.
That only works for valid code. One of the main arguing points is which is more error-prone - and faulty code will need to be fixed by hand before you run it through a tool.
Sure. Let's say you have a variable declaration like this:
var foo = 'foo',
bar = 'bar';
And modify it to this:
var foo = 'foo,
bar = 'bar';
baz = 'baz';
You can spot the error, but a tool to convert var styles won't. It will (likely, I haven't run it) correctly convert the first var statement and leave the implicit global intact because it doesn't want to modify behavior.
The above mistake is much less likely if you're using this style:
var foo = 'foo';
var bar = 'bar';
And because that is correct code, your tool can correctly convert it to the single-var style.
Actually, the Pretty Diff tool I linked to told me what the error was, an unterminated string. This is something most automation tools would catch. They may not fix your broken unparsable code for you, but they will likely tell you its broken and where to look.
40
u/sime Mar 27 '15
That is the first JS style guide where there isn't anything stupid in it and I actually agree with what it says. The closest thing to a disagreement is single quotes only for strings, and that is only because I tend to mix them up myself.
They even got
varright which says less about them and more about the state of "JS culture". (I would have expected onevarper line to be an obvious no brainer which didn't need to be stated.)