5 ms·
"Note how the errors pop out in the comma-first style." So what? Any decent IDE will highlight this error for you anyway.
by Pheter 16y ago
"Note how the errors pop out in the comma-first style."
So what? Any decent IDE will highlight this error for you anyway.
- edanm 16y agoNot the ones I use. But actually, there are other benefits: easier to add new lines to the list (just duplicate the previous one and change the value; no need to remember to add a comma at the end of the last item). Also, someone mentioned another (small) benefit in the comments: when diff'ing files, using comma-first will only cause one line of difference, instead of two. These are all small benefits, but since I can't think of any disadvantages to the comma-first style, I think I'm a new "convert".
- Hovertruck 16y agoFor anyone interested, the JS Tools bundle for TextMate alerts you of errors in your JS every time you save. http://github.com/johnmuhl/javascript-tools-tmbundle http://github.com/johnmuhl/javascript-tools-tmbundle
- Pheter 16y agoI don't use JS, but in PHP you can add a comma after the last item, which I usually do, and therefore I don't have the problems that you encountered. Of course, I believe that people should do what works best for them, and if you find comma first easier to work with, then great! Edit: And in response to your first comment about your IDE not supporting this: Is it not trivial to identify a syntax error in JS when you attempt to run it? Surely the intepreter (browser?) will notify you of the line that the syntax error occured on?
- edanm 16y agoYeah, I'm also used to adding a comma after the last item (in C, C++, Python). One of the problems is that this is an error in Javascript, but only in IE. Which means code will work fine while you develop, but when it comes time to test, it will suddenly stop working. The good thing about this way is that it's also very easy for humans to spot the error. Bottom line, catching the error while you code is always better than catching it after you compile. Also, this method has the advantage of working in all the languages I work in.