News for hackers. Stuff that matters.
Re:Typing Nix by wereHamster on Friday June 23, 2017 @11:54AM (#14620053)
Is there any real disadvantage to comma-first, other than aesthetics (which is entirely a personal preference)?
Re:Typing Nix by ykler on Friday June 23, 2017 @12:30PM (#14620413)
Yes, when the commas are at the beginning of the line they are really obvious. I have used commas-first style in JavaScript, and it definitely reduced the amount of times I forgot a comma.

I wonder if people's aversion to commas first has something to do with the fact that commas have a very familiar use in ordinary writing, and there they always follow a word. It is very common to see BNF grammars written with leading vertical bars, and no one seems to mind that -- in fact it would be unusual to use trailing vertical bars.

By the way, a bunch of languages permit a trailing comma after the last element of a list. This is also nice because it means that if you put each list item on a line, the list items all have the same format (thing plus comma). With the Haskell syntax, you lose this, but there is no reason a language couldn't support a leading comma before the first element of a list.

Re:Typing Nix by icebraining on Friday June 23, 2017 @01:28PM (#14620958)
My aversion has to do with the fact that the first element doesn't have one. The irregularity is annoying not just aesthetically, but also if you want to swap lines around, etc.
Re:Typing Nix by cwyers on Friday June 23, 2017 @03:55PM (#14622243)
But there's always a line without a comma -- comma-last has it on the last line instead of the first. So you can have the same line-swapping problem in either arrangement. Comma first just makes it easier to spot.
Re:Typing Nix by icebraining on Friday June 23, 2017 @04:19PM (#14622420)
But there's always a line without a comma -- comma-last has it on the last line instead of the first.

Not if the language allows trailing commas on the last line, like Python and Go do.

Re:Typing Nix by coldtea on Saturday June 24, 2017 @06:20AM (#14625104)
Not if you allow dangling commas (trailing commas as the sibling comment calls them, I think it's the more generic term)...

Then you have a comma at the end in ALL lines, including the last one, without an issue. That was what I proposed above (and lots of languages do it, I think JS is adding it too).

Re:Typing Nix by coldtea on Friday June 23, 2017 @12:40PM (#14620499)
The wrath of God that it imposes on people who think it's acceptable, for one...
Re:Typing Nix by weberc2 on Friday June 23, 2017 @12:30PM (#14620409)
It's another thing to learn, and the total learning curve is the product of all of these idiosyncrasies (and features) (not the sum). And there's absolutely no advantage to comma-first.
Re:Typing Nix by Jweb_Guru on Friday June 23, 2017 @02:29PM (#14621480)
It makes git diffs inaccurate compared to trailing commas.
Re:Typing Nix by mbrock on Friday June 23, 2017 @02:58PM (#14621772)
How so?
Re:Typing Nix by viraptor on Friday June 23, 2017 @09:19PM (#14623895)
Inserting a new element with comma-first changes 2 lines:

   - { old-one
   + { new-one
   + , old-one
While trailing commas allow you to insert an element anywhere with just one line addition.

This doesn't break anything, but it makes looking at "git blame" so much easier.

Re:Typing Nix by dragonwriter on Friday June 23, 2017 @09:37PM (#14623957)
This is only true if you insert at the head. And it's not really leading comma placement but the choice to put the first element in the line with the brace that is the culprit, though both are typical of comma-first.
Re:Typing Nix by viraptor on Saturday June 24, 2017 @05:20AM (#14624992)
With separating comma, it either affects the first or the last position, depending on where you put the commas. But those are the most common places you modify lists.