7 ms·
My faint hopes for trailing comma support are now crushed.
by Jare 13y ago
My faint hopes for trailing comma support are now crushed.
- TallGuyShort 13y agoI'm actually very confused by it - I thought the specification for ECMAScript 3 already specified trailing comma support for JSON. Will need to look it up...
- masklinn 13y agoECMAScript 3 did not allow trailing commas in object literals, its section 11.1.5 is: ObjectLiteral : { } { PropertyNameAndValueList } whereas ES5's is: ObjectLiteral : { } { PropertyNameAndValueList } { PropertyNameAndValueList , } And while JSON is strongly inspired by javascript's object notation, it is not actually javascript: their strings are subtly incompatible (JSON allows U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR in quoted strings, javascript does not).
- rpedela 13y agoWhat 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.
- 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.
- undershirt 13y agoI was crossing my fingers for that too. I create JSON files a lot. It's annoying when I'm _reordering_ elements separated by newlines. It's annoying when I'm generating JSON files and I have to code in a special case to skip the comma. It breaks the consistency that I just desire as a programmer.
- Touche 13y agoWhy do you manually code json?
- VMG 13y agobecause that is what json is for
- optymizer 13y agono, that's not what json for. JSON is for exchange data between machines. We already have data interchange formats for humans, we call those 'languages'.
- mercurial 13y agoYes, yes. And we could also have everything as binary. Now, UNIX people decided long ago to use plain text to communicate between processes, mostly because it's infinitely easier to read - and makes it possible to edit by hand if you need to. Have to interface with a REST API which consumes JSON and you want to do some testing? Open your text editor anywhere curl is installed, and you're done. That's pretty damn convenient.
- TeeWEE 13y agoTrailing comma's, really?? Its is so fucking ugly and inconsistent. Either ALWAYS have traling commas, or never have it. And since the meaning of a comma is separate two items, a trailing comma makes no semantical sense, the only reason you want it because A) youre lazy B) you dont know howto properly serialize to json (youre doing string manipulation probably C) you never heard about the .join function D) you dont know how to read a diff E) you dont do syntax checks before you deploy your code
- Zikes 13y agoA) Wat. B) Somebody's gotta write those serialization libraries, and they probably do a fair amount of string manipulation to do so. C) You can't .join data streams without buffering, which defeats the purpose. D) Adding commas on a preceding line every time you add a new item to a list can pollute diffs. E) Trailing commas are syntactically correct in ECMAScript 6, and supported by a fair few other languages.
- bcj 13y agoTrailing commas reduce cognitive load. I don't need to consider whether an element I'm adding is the last item in a set; there isn't an edge case. Also, I can more quickly scan a DIFF and see the change in a file.
- Jare 13y agoIt's fine to disagree, but you need to calm down.
- 6cxs2hd6 13y agoAnyone compiling a list of talking points for why s-expressions aren't so crazy after all, should add this to the list. (Just append it to the list, no comma required; i.e. pun sorta intended.)