3 ms·
Here's an article about why preceding comma is very convenient: http://ajaxian.com/archives/is-there-something-to-the-crazy-comma-first-style?utm_source=feedbu
by DTrejo 16y ago
Here's an article about why preceding comma is very convenient:
http://ajaxian.com/archives/is-there-something-to-the-crazy-comma-first-style?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ajaxian+%28Ajaxian+Blog%29 http://ajaxian.com/archives/is-there-something-to-the-crazy-...
More specifically, in which is it easier for you to find the error?
// error in standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog"
e = "elf",
f = "fly",
g = "gnu",
h = "hat",
i = "ibu";
// error in comma-first style
var a = "ape"
, b = "bat"
, c = "cat"
, d = "dog"
e = "elf"
, f = "fly"
, g = "gnu"
, h = "hat"
, i = "ibu"
;
- davej 16y agoYeah, I understand why, particularly when old IE browsers don't allow a comma trailing the final declaration. I just find it ugly as hell.
- jsankey 16y agoUnfortunately trailing commas still break IE7, which I wouldn't yet classify as old enough to ignore.
- davej 16y agoI'm not ignoring it but my code always runs through JSLint each time its saved and that picks up misplaced commas for me. Also we're not talking about client-side javascript here; fortunately Node.js uses the V8 Javascript engine, not the IE7 one. :)
- joelhaasnoot 16y agoIf that's so, why do we not see this in other mainstream languages? While I see the slight advantage of seeing errors, that is the first thing node sees. I use either nodemon or cluster, which both monitor your program on saving your code. When you think you're ready to go, save and see if it has no compile errors.
- deleted 16y ago[deleted]
- Dobbs 16y agoIt seems to be the convention within the Haskell world.
- bartonfink 16y agoI do this all the time on large SQL statements. Otherwise, I rarely use the comma operator, so it hasn't come up.
- jberryman 16y agoI don't know if haskell counts as a mainstream language, but it's pretty common to see this pattern in a module's export list. I go back and forth.
- jerf 16y agoHaskell's an odd case; experienced Haskell users are likely to be thinking of the comma as less of a "separator" than a "combinator" constructing a tuple, and preceding-combinator-on-newline is an idiomatic style. Which doesn't disprove your point, I'm just saying it's an edge case. This is after all the language community that interprets a semicolon (as used in most languages) as a combinator too.
- btmorex 16y agoI'd rather occasionally have comma bugs than make all my code horrendously ugly. Also, most people don't set their tabstop to 2 characters, which means you have to use space key twice in every variable declaration. That's got to be annoying.
- DTrejo 16y agoMany node projects use soft tabs set to two spaces.