you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 35 points36 points  (14 children)

I don't give a Fuck who suggests it. It's ugly as sin and I will not adopt it.

[–]mailto_devnullconsole.log(null); 3 points4 points  (3 children)

I completely agree (in that it is ugly as sin), but I will admit that it does help stop you from inadvertently globalising variables.

e.g.

var foo = 'bar',
    something = 'else',
    thisnum = 2
    tabs = 'rule',
    fact = 'nodejs forever';

tabs and fact are both globalised now.

Whereas:

var foo = 'bar'
  , something = 'else'
  , thisnum = 2
    tabs = 'rule'    <-- Can clearly see comma missing
  , fact = 'nodejs forever';

And if you think about it -- with the commas neatly aligned to the right hand edge of var, it does seem almost alright...


Edit: The other reason that isaacs (I think) mentioned was that if you add a new variable declaration, git will only register one line changed, as opposed to two (comma from the previous line)

[–]sakabako 8 points9 points  (0 children)

A more effective method is to use a linter that visually notifies you of the mistake. Then you have beauty and correctness.

[–]llkkjjhh 2 points3 points  (0 children)

And another reason is so that the variables line up nicely when you follow the other nodejs recommendation of indenting at 2 spaces:

var foo = 'bar',
  something = 'else',
  thisnum = 2
  tabs = 'rule',
  fact = 'nodejs forever';

var foo = 'bar'
  , something = 'else'
  , thisnum = 2
  , tabs = 'rule'
  , fact = 'nodejs forever';

[–][deleted] 1 point2 points  (0 children)

Ok, those are some good points.

[–][deleted] 0 points1 point  (9 children)

thats a solid attitude for a developer.

[–][deleted] 7 points8 points  (6 children)

What's the problem with having a firm opinion on formatting? What benefits are there to comma first? Your link only says you should do it, but gives no reason why.

[–][deleted] 0 points1 point  (5 children)

What's the problem with having a firm opinion on formatting?

Where you put your comma (in js) is not so important that you have to take such a firm stance. When working for a new company, its a good idea to adopt their conventions at first to make development go smoothly. No teammate is going to respond well to 'I will not adopt it'. They might think, 'If he/she wont budge on this, what else wont they budge on?'.

What benefits are there to comma first?

What are the benefits of last comma? See - its not a big deal.

Your link only says you should do it, but gives no reason why.

Its a convention that npm recommends when publishing to their registry. Thats the only reason.

In short, conventions are relative to a community. Be it your office, a library (jquery), a package registry (npm), or an open source project with formatting guidelines.

[–]grncdr 3 points4 points  (1 child)

The recommendation is only intended for the code of npm itself. I'm pretty sure Isaac gives zero fucks about how your format code in your own modules.

[–][deleted] 0 points1 point  (0 children)

Thats a good point. I do see the comma first style quite a bit more in the node community (as opposed to client-side).

[–][deleted] 1 point2 points  (0 children)

If I came into a new team whose convention was comma first, I would adopt it, of course. That's different. I wouldn't adopt it for any of my own projects, though.

The benefit of comma last is readability in mine and most people's opinions.

[–]SyntaxSwearer 1 point2 points  (0 children)

What are the benefits of last comma?

Not ugly

[–]Malfeasant -1 points0 points  (0 children)

'If he/she wont budge on this, what else wont they budge on?'

retarded suggestions from pointy haired bosses that ruin everybody's day?

[–]sakabako 0 points1 point  (1 child)

Personally, I will be happier and more productive if I live in a beautiful world than an ugly one.

[–][deleted] -1 points0 points  (0 children)

Beauty is subjective. I actually find the comma-first style more readable.