Re:Regarding JavaScript trailing commas
by tikhonj on Saturday April 09, 2016 @12:31AM
(#11459921)
I've actually come to like a weird style popular in the Haskell world, leading commas:
It's weird, but it's actually pretty convenient. I think it has all the same properties the article argues for, but I don't want to figure it out for sure at the moment.
[ Parent
| on HN ]
Re:Regarding JavaScript trailing commas
by tigershark on Saturday April 09, 2016 @03:17AM
(#11460324)
In my eyes this is really awful. Furthermore, if you move the first entry in the last place as is you get a syntax error.
So it has all the disadvantages of the code without trailing commas, plus it makes your eyes bleed if you are used to read pretty much anything apart Haskell code.
I like that Data.Sequence bypasses this whole issue by just not doing anything special:
empty
|> ("one" , 1)
|> ("two" , 2)
|> ("three", 3)
Edit: It's interesting that, when we have things that are supposed to commute, we use infix operators that create a layout that makes it difficult to reorder them.
Re:Regarding JavaScript trailing commas
by statictype on Saturday April 09, 2016 @01:34AM
(#11460096)
I've always found this style a lot better and can't figure out why people don't use it.
Adding items to the end of a list, tuples to a dictionary, arguments to a function etc... is more common then adding them to the start.
No way. What you if had to cut and paste the first item?
Re:Regarding JavaScript trailing commas
by dllthomas on Saturday April 09, 2016 @04:00PM
(#11463025)
Then it's extremely obvious that it needs fixing, and your cursor is usually right there to make the change.
It is marginally more difficult than leaving in trailing commas, but way better than adding missing unaligned commas at EOL.
I think the argument would be that this is rarer
For the love of god though don't suddenly start using this style in a project that doesn't (I've had to deal with it)
Re:Regarding JavaScript trailing commas
by shadeless on Saturday April 09, 2016 @01:28AM
(#11460075)
It's worth mentioning that Elm uses this style: http://elm-lang.org/docs/style-guide#types
I was initially surprised by this but now knowing that the creator comes from a Haskell background, it makes sense that he would prefer it.