Hacker News new | ask | show | jobs
by rpedela 4628 days ago
What does trailing comma support get you?
4 comments

It 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.
> 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.

Join doesn't help to stream to JSON from a database cursor. Unless you buffer the response first which is pretty horrid.
Fair point.
For 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.
This is why you prepend the comma before every succeeding item in a list or map.
This 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.
You'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.
This seems to only move the problem to the first item instead of the last one, not solve it.
The ability to be lazy.
Doesn't seem like a good reason for a spec. Laziness is partly why Javascript as a language is so messed up.
If 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.
It is a terrible language, though. That's common knowledge.

It is, however, wrong to say it's terrible because of laziness.

I 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.
I 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.

"wonderful, awe-inspiring, mind-blowing parts"

Honest question: Such as?

LOL! 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.
The ability to use a for-each loop rather than an iterator or iterated for loop.