Seriously! Every language should support this. Not just for arrays but in argument lists too! Python does a good job here but I can't think of anything else which does.
Depending on other syntax facets, that can create ambiguity.
Does that trailing comma represent nothing (the end of the list) or an undefined/null/empty/whatever item (an extra item adding to the length of the list?
Even if the meaning is completely unambiguous as far as the language is concerned, that doesn't necessarily make it intuitive to humans especially in a mixed language scenario.
The real benefit of comma-first-style is that it becomes immediately apparent while editing the code that something is missing when you forget a comma.
(I already posted this reply on his blog, but seems like it has been deleted along with a bunch of other disagreeing comments there)
What if you want to add a new element at the top? And even when you need to add it at the end, if you use a decent editor, it won't make a difference. For example, with vim:
(Place cursor on last element)
A,<cr>myNewElement
As opposed to left comma style:
o,<space>myNewElement
Only 3 extra keysrokes for both cases. (<cr> is the Enter key, by the way)
I can't believe this kind of post could make it to the front page of Hacker News.
Oh come on! Have a sense of humor. I couldn't have made this post more tongue-in-cheek!
I took a really small code-formatting issue and turned it into a faux holy war using faulty logic, cherry-picked facts, and doofy ad hominem attacks in the tradition of Bloom County:
I didn't get that this was a joke. It's my fault, I read the first few lines and thought that you were serious and that it was a waste of time to continue reading. I actually came here to write, "this must be a joke."
I always hated that the top element is shifted over one char when people put the commas on the left. I don't find it "clean" at all. All items lined up evenly on the left with commas on the right looks way better to me.
21 comments
[ 3.9 ms ] story [ 51.6 ms ] threadDoes that trailing comma represent nothing (the end of the list) or an undefined/null/empty/whatever item (an extra item adding to the length of the list?
Even if the meaning is completely unambiguous as far as the language is concerned, that doesn't necessarily make it intuitive to humans especially in a mixed language scenario.
Who says you have to add your elements at the end? If OP is going to be so rude and absolutist, he should really pick a stronger argument.
What if you want to add a new element at the top? And even when you need to add it at the end, if you use a decent editor, it won't make a difference. For example, with vim:
(Place cursor on last element) A,<cr>myNewElement
As opposed to left comma style: o,<space>myNewElement
Only 3 extra keysrokes for both cases. (<cr> is the Enter key, by the way)
I can't believe this kind of post could make it to the front page of Hacker News.
Personally, I think it's the creative use of "Dink-butt".
http://webcache.googleusercontent.com/search?q=cache:http://...
Also, what a gratuitously obnoxious post. Flagged as inappropriate.
I took a really small code-formatting issue and turned it into a faux holy war using faulty logic, cherry-picked facts, and doofy ad hominem attacks in the tradition of Bloom County:
http://www.berkeleybreathed.com/pages/09bloomlibrary.asp
My post might be "gratuitously obnoxious," but your taking offense at it is amusingly pretentious.