To me, consistency is important. All of my codebase is traditional comma postfix, so I'll keep using that; however, maybe with some new projects I'll try on the comma prefix pants and see if it helps.
Thanks for the link!
To me, consistency is important. All of my codebase is traditional comma postfix, so I'll keep using that; however, maybe with some new projects I'll try on the comma prefix pants and see if it helps.
Thanks for the link!
To me
, consistency is important
. All of my codebase is traditional comma postfix
, so I'll keep using that
; however
, maybe with some new projects I'll try on the comma prefix [...]
... using typography in a typographically sensible way is far more important to readability than an arbitrary "consistency" of punctation. We're humans, not computers, after all.They're always correct, they copy without any editing, and the "var"s line up to show that it's a block of assignments the same as commas or whitespace.
var a = 2; var b = 4; var c = { blah: "whatever" };
Leaving out a semicolon has no effect. They can be copied without any fuss. It's easy.
x = {[
{ id: 1, data: 0 },
{ id: 2, data: 0 }
],
[
{ id: 3, data: 0 },
{ id: 4, data: 0 }
]} var foo = 1,
bar = 2
baz = 3
In 90% of the cases the code will run the same whether or not there is a comma on line 2, but in the other 10% you will get burned in odd ways now that `baz` is a global variable.* There's a missing semicolon on line 2
* There's a missing semicolon on line 3
* baz was being used before it was defined.
That's just in a global context. When it's in a function you get a little more:
* the baz line is indented too far - because it's being interpreted as a new statement.
Sure, you could eyeball your code looking for this. Or just use an automated tool that'd do it for you
It's so ugly to me that the whole idea seems like it could be a troll.
And let me play the advocatus Dei
, because that actually looks quite readable
.
Though, more seriously, using English (a natural language) to try to make an
appeal to absurdity about the format style of a formal language, is plain
absurd. To me, consistency is important
. All of my codebase is traditional comma postfix
, so I'll keep using that; however
, maybe [...]
Which is more confusing than either of our consistent examples. Unless I misunderstood your point.What convinced you? I read it and saw something wildly different, which is best reserved for a good reason. The reason appears to be visual recognition of delimiter mistakes that the parser will catch anyway.
The gist contains examples of various mistakes in both styles. Most of the errors are syntax error which will be immediately rejected by a parser. While the comma first errors are generally more obvious, they are silently bad by unexpectedly returning undefined. The standard "var" example is silently bad by leaking vars into the global scope when chaining initializers on a single "var". My conclusion from these samples is that comma prefix formatting only practically helps to prevent hidden mistakes in chained "var"s. Putting each variable declaration on a line of its own is far less distracting than reformatting every list and object.
Sample comma first style error. This seems like a strange thing to do, but I'm unfamiliar with this style.
return
{ a : "ape"
, b : "bat"
} // returns undefined,
// then creates a block with two named statements.
Sample standard style error: var a = "ape eat banana",
b = "bat, allowed to fly",
c = "cat toy",
d = "dog chasing the mailman,"
e = "elf lord",
....
// leaks "e" into global scope return
{ a : "ape",
b : "bat"
}
The error here has no relation to the commas.