News for hackers. Stuff that matters.
Re:Best Practices Exist For A Reason by jashkenas on Wednesday May 02, 2012 @04:27PM (#3920995)
To play at devil's advocate, please don't. Otherwise you should have written your comment like this:

    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.
Re:Best Practices Exist For A Reason by asolove on Wednesday May 02, 2012 @04:38PM (#3921061)
Why does nobody ever mention the obvious solution? Separate var statements.

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.

Re:Best Practices Exist For A Reason by mnutt on Wednesday May 02, 2012 @08:09PM (#3921789)
With separate var statements, you never end up with this situation:

    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.
Re:Best Practices Exist For A Reason by Isofarro on Thursday May 03, 2012 @04:08AM (#3922866)
JS Lint is your friend in this case. It will log that

* 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

Re:Best Practices Exist For A Reason by chc on Wednesday May 02, 2012 @06:07PM (#3921460)
You can only put var at the beginning of variable declarations, but there are many other places that commas are used as a separator. So that "solution" doesn't apply in general.
Re:Best Practices Exist For A Reason by asolove on Wednesday May 02, 2012 @09:02PM (#3921927)
I think I might have explained myself poorly. I'm suggesting using separate var statements for each assignment, e.g.:

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.

Re:Best Practices Exist For A Reason by ricardobeat on Thursday May 03, 2012 @12:22AM (#3922368)
Problems with semi-colons usually arise in object usage. So your solution is very specific.

    x = {[
      { id: 1, data: 0 },
      { id: 2, data: 0 }
    ],
    [
      { id: 3, data: 0 },
      { id: 4, data: 0 }
    ]}
Re:Best Practices Exist For A Reason by slexaxton on Wednesday May 02, 2012 @06:11PM (#3921475)
Most people also apply this to object literals. There are no var statements in this situation.
Re:Best Practices Exist For A Reason by andywhite37 on Wednesday May 02, 2012 @11:16PM (#3922225)
Separate vars is what I prefer to do, but JSLint actually recommends that you change multiple var statements to a single var with variables separated by commas (and with a semicolon at the end of course!). (And also all var declarations at the top of the function...).
Re:Best Practices Exist For A Reason by rapind on Wednesday May 02, 2012 @06:28PM (#3921523)
This. I admire code that reads like english. Leading commas are a terrible idea in my humble opinion.

It's so ugly to me that the whole idea seems like it could be a troll.

Re:Best Practices Exist For A Reason by UnFleshedOne on Wednesday May 02, 2012 @07:00PM (#3921630)
I use leading commas in any list that is not one liner in C++. This way the code looks pretty, and that is way more important that code that reads like english. :) (I shudder from dread every time I look at applescript...)
Re:Best Practices Exist For A Reason by amackera on Friday May 04, 2012 @02:01PM (#3929547)
Even in your example you were consistent, so was I. Inconsistency would be

  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.
Re:Best Practices Exist For A Reason by slowpoke on Thursday May 03, 2012 @02:41AM (#3922678)

    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.