Live data from Hacker News

Regarding JavaScript trailing commas

dontkry.com

31–40 of 48 posts

Re: Regarding JavaScript trailing commas

#31
post #17

I've actually come to like a weird style popular in the Haskell world, leading commas : { one = 1 , two = 2 , three = 3 } 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.

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

#33

I would argue that the trailing comma diff issue is an artefact of the fact that diff works at the text level, not at the syntax level (I can only hope this might be a thing someday)

Sounds like an absolute nightmare of a problem to solve. And a maintenance nightmare.

Languages change over time.

Re: Regarding JavaScript trailing commas

#34
post #4

I'm a Python programmer. In Python, trailing comma are idiomatic, so I welcome this. Perhaps I'm just a lazy bastard, but it makes cut & paste a lot easier.

Ditto, from the Perl side of things. I'm a JS coder for the last few years, and I find I really hate a lot of the style conventions - they seem much more oriented towards "because I said so" than "because it's actually better".

Many common JS conventions are because they were critically important at a.) the time the lead programmer learned Javascript or b.) the time the codebase was originally written.

Trailing commas are certainly in that category. When I started getting into JS seriously in 2007, this wasn't a nitpick: your code would be outright broken in IE6 if you had a trailing comma, and would fail with a syntax error. This was a leading cause of IE bugs, since developers often developed in Chrome or Firefox (which handled them fine) and it was ridiculously difficult to trace it down.

Ditto a lot of other conventions. It was common to use innerHTML instead of DOM manipulation because IE was ridiculously slow at DOM manipulation (React just fixed this in their codebase this week). It was common practice to wrap every file in a closure because all your variables would pollute the global scope - now we have CommonJS modules and bundlers to handle this. It was common to avoid closures in favor of prototypes & _ naming conventions because Firebug & Chrome Devtools couldn't inspect variables in closures.

All of these are terribly obsolete now, and there's no reason to adopt them on a new green-field project. But the point of coding conventions is uniformity with existing code, so if you're inheriting a codebase that was written when these were actually important, it's often good to conform just for consistency's sake.

Re: Regarding JavaScript trailing commas

#35

Earlier quoted context omitted.

> CoffeeScript has done a good job of this And that language shouldn't be used by beginners in 2016 due to its uncertain fate in the long run as its creator kind of abandoned the project. Furhtermore ES2015 adds many CS features to the language. Don't know about LiveScript, but frankly that whole transpilation thing is a mess. People don't use Transpilers for Python or Ruby. They work with the language quirks.

Some of the features of ES6 are pretty neat. Some of them are just crap piled on crap, which bloat out the language for marginal benefits at best. Unfortunately, many of the ES6 features inspired by CoffeeScript features are completely unoptimized and an order of magnitude slower in cutting-edge browsers than the CoffeeScript versions. Even more unfortunately, they don’t work at all in lots of browser versions people…

So use Babel, as long as you're using a compiler anyway?

Re: Regarding JavaScript trailing commas

#36

Earlier quoted context omitted.

Some of the features of ES6 are pretty neat. Some of them are just crap piled on crap, which bloat out the language for marginal benefits at best. Unfortunately, many of the ES6 features inspired by CoffeeScript features are completely unoptimized and an order of magnitude slower in cutting-edge browsers than the CoffeeScript versions. Even more unfortunately, they don’t work at all in lots of browser versions people…

So use Babel, as long as you're using a compiler anyway?

Not my personal cup of tea (I don’t particularly like the ES6 syntax, and as I mentioned many of the nicer features are horribly inefficient in current browsers), but use whatever you like!

Re: Regarding JavaScript trailing commas

#37
post #17

I've actually come to like a weird style popular in the Haskell world, leading commas : { one = 1 , two = 2 , three = 3 } 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.

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.

Re: Regarding JavaScript trailing commas

#38
In my opinion it is just a matter of personal taste, if I move some code without trailing commas I make sure that the commas are in the right place. This actually can be seen as an advantage given that blind copy and paste is the source of all evils, so a syntax error will force you to reconsider what you have just done blindly. All in all I don't see a problem in using either styles, it's only one character difference at the end.

Re: Regarding JavaScript trailing commas

#39
post #33

I would argue that the trailing comma diff issue is an artefact of the fact that diff works at the text level, not at the syntax level (I can only hope this might be a thing someday)

Sounds like an absolute nightmare of a problem to solve. And a maintenance nightmare. Languages change over time.

I would imagine any version control system attempting to solve this problem would focus very closely on one particular language or development system. Any pragmatic solution would also have to be a highly opinionated one.

For a related idea, see Facebook's Haskell system, in which only type-safe code is allowed to be checked into the respository:

https://code.facebook.com/posts/745068642270222/fighting-spa...

Re: Regarding JavaScript trailing commas

#40
post #32

Right. Anything but losing the damn commas. nineties { dude: true awesome: true rad: true }

Well, that opens up a whole new can of syntax worms... But yeah, all of this stuff just makes me more convinced that Lisp syntax is the best ever.

Lisp uses comas in macro evaluation, but not lists and dictionaries. Then you have reader macros. Lisp syntax can be arbitrarily complex.
Post reply on HN