Hacker News new | ask | show | jobs
by blt 4400 days ago
The last line often has something extra - a semicolon or parentheses - or something missing, like no comma in an enum or no `&&` in a long chained conditional. Maybe that triggers the "gorilla on the basketball court" effect, and we miss the error in the meat of that line because we're focusing on the difference.
2 comments

It is one of the more foolish things that programming languages leave around though. If I'm writing an enum which is bracket closed, then don't make leaving in an extra comma an error if it's unambiguous.

As I recall I think most of the brackety languages actually do ignore it now? So it's a good way to mitigate at least that small problem.

Hack (Facebook's PHP-derived statically typed scripting language) definitely does allow it, which is nice.

In fact, over on #hhvm I was told that Facebook's Hack style guide requires a trailing comma, which I think is a good thing and will catch a lot of silly errors.

Yes, I noticed this a lot with Javascript: I would often have a trailing comma at the last element of an array or object. Most browsers would let it go unremarked but it was stupidly a halting error in some versions of IE.

Anyway, when I made my own Vim syntax highlighter for JSON, I spent a fair amount of effort in getting such a trailing comma highlighted as an error: https://github.com/elzr/vim-json