Live data from Hacker News

Regarding JavaScript trailing commas

dontkry.com

41–48 of 48 posts

Re: Regarding JavaScript trailing commas

#41
post #32

Earlier quoted context omitted.

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.

It's not that the symbol comma is bad. Lisp uses it as a prefix to unquote a form, which is totally different from the use as a separator.

Re: Regarding JavaScript trailing commas

#42

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 differen…

For compiled languages like Rust, you might be correct, though even there I use trailing commas, specifically for the reason mentioned. It reduces bugs when you add or swap around array elements.

In a compiled language you catch this because it's a syntax error. In JavaScript, it might be missed through every code review (because it's subtle) and and then break on release to you production system.

So it's not just style, it can help reduce bugs.

Re: Regarding JavaScript trailing commas

#43
post #32

Earlier quoted context omitted.

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.

The commas do something in backquote syntax! They are operators, effectively.

In the Scheme backquote (dubbed quasiquote), the spec says that the read syntax ,X produces (unquote X). You can omit the comma, and then you just have X.

This is totally different from a comma which just punctuates syntax.

Re: Regarding JavaScript trailing commas

#44
I tend to remove them because trailing commas break JSON. The similarities between JS and JSON are small enough for me to get confused over it and I'd rather remove the cause of potential errors there altogether.

Re: Regarding JavaScript trailing commas

#45
post #32

Earlier quoted context omitted.

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.

macro and comma is fully unrelated. The comma in backquote expressions is not even limited to lists. Commas are used in backquote forms to force evaluation.

For example one can write a vector of three elements, where the second element is computed:

    `#(1 ,(first *features*) b)
Backquote list forms happen to be used in some macros as a kind of template forms. Macros can be defined without them and backquote forms are also used elsewhere in Lisp.

Re: Regarding JavaScript trailing commas

#46
post #22
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.

No way. What you if had to cut and paste the first item?

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.

Re: Regarding JavaScript trailing commas

#47
post #45

Earlier quoted context omitted.

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

macro and comma is fully unrelated. The comma in backquote expressions is not even limited to lists. Commas are used in backquote forms to force evaluation. For example one can write a vector of three elements, where the second element is computed: `#(1 ,(first *features*) b) Backquote list forms happen to be used in some macros as a kind of template forms. Macros can be defined without them and backquote forms are a…

They are not "fully unrelated". The backquote syntax for constructing lists was primarily designed for macro programming. See the paper Evolution of Lisp by Guy Steele and Peter Gabriel:

"Macros took a major step forward with Lisp-Machine Lisp, which consolidated the various macro-defining techniques into two standardized features that were adopted throughout the MacLisp community and eventually into Common Lisp. The macro defining operator DEFMACRO provided list-structure destructuring to arbitrary depth; the backquote feature provided a convenient and concise pseudo-quoting facility. [ ... ] Backquote and DEFMACRO made a big difference. This leap in expressive power, made available in a standard form, began a new surge of language extension [...]" [3.3]

Re: Regarding JavaScript trailing commas

#48
post #45

Earlier quoted context omitted.

macro and comma is fully unrelated. The comma in backquote expressions is not even limited to lists. Commas are used in backquote forms to force evaluation. For example one can write a vector of three elements, where the second element is computed: `#(1 ,(first *features*) b) Backquote list forms happen to be used in some macros as a kind of template forms. Macros can be defined without them and backquote forms are a…

They are not "fully unrelated". The backquote syntax for constructing lists was primarily designed for macro programming. See the paper Evolution of Lisp by Guy Steele and Peter Gabriel: "Macros took a major step forward with Lisp-Machine Lisp, which consolidated the various macro-defining techniques into two standardized features that were adopted throughout the MacLisp community and eventually into Common Lisp. The…

http://repository.readscheme.org/ftp/papers/pepm99/bawden.pd...
Post reply on HN