5 ms·
What does trailing comma support get you?
by rpedela 13y ago
What does trailing comma support get you?
- oneeyedpigeon 13y agoThe ability to be lazy.
- rpedela 13y agoDoesn't seem like a good reason for a spec. Laziness is partly why Javascript as a language is so messed up.
- nilliams 13y agoIf I could down-vote this lazy, drive-by, language bashing I would. Back up 'so messed up' or keep comments like this to yourself, they don't help the discussion.
- rpedela 13y agoLOL! Obviously I struck a nerve. I thought it was obvious to everyone the problems of Javascript as a language. For laziness, how about weak typing and defining a class using a function. Plenty more examples, but you can do your own research if you are curious. BTW I like and use Javascript, but it is still a crap language.
- lucian1900 13y agoIt is a terrible language, though. That's common knowledge. It is, however, wrong to say it's terrible because of laziness.
- oneeyedpigeon 13y agoI really don't think it's fair to say it's a terrible language. It does have some terrible, horrible parts. But it also has some wonderful, awe-inspiring, mind-blowing parts. It's just not a MOR language - you have extreme lows and awesome highs.
- MichaelGG 13y ago"wonderful, awe-inspiring, mind-blowing parts" Honest question: Such as?
- oneeyedpigeon 13y agoclosures, prototypical inheritance, the syntax for object/array literals. and I know it's not strictly part of the language, and it's deeply unfashionable to say so, but I'm quite a fan of the DOM, too.
- MichaelGG 13y agoClosures and literals are pretty basic things for many languages and very well-known. Prototypical inheritance may have gotten much more exposure via JS, but I'm not overly impressed with it, and I hardly think it makes up for the rest of the language.
- oneeyedpigeon 13y agofair enough; JS introduced me to closures, so I'm a bit biased.
- AYBABTME 13y agoI would say that Javascript is not too bad a language because it has those nice parts. But overall, it's still a language that feels weird given all the bad parts. I still don't get around how `this` can be so broken.
- mjmahone17 13y agoFor large code bases, you don't break git blame by adding in new arguments. And it's one less thing to think about when editing your code: always add a comma, never worry about errors because you need to add a comma to the line above.
- codehero 13y agoThis is why you prepend the comma before every succeeding item in a list or map.
- swift 13y agoThis is what I do, but it basically just has the effect of making the first item special instead of the last. That's usually better in practice, though.
- peferron 13y agoThis seems to only move the problem to the first item instead of the last one, not solve it.
- Pxtl 13y agoYou've slightly improved the problem by moving it away from the last item on the list, but you've now screwed up the first item. You can no longer insert a first-item using the same format, and instead of a trailing comma bug you can get a starting comma bug.
- swift 13y agoIt simplifies generating JSON, since you don't need a special case for the last item, and it simplifies editing it, since you don't need to do something special when adding a new item at the end. I can't see any benefit to not having it, honestly.
- mercurial 13y ago> It simplifies generating JSON, since you don't need a special case for the last item In which language can't you do array.join(",")? You can even do that in Java with one of the myriad of string libraries. I haven't hand-coded joins since (at least) six or seven years.
- batbomb 13y agoThe ability to use a for-each loop rather than an iterator or iterated for loop.