News for hackers. Stuff that matters.
Re:Best Practices Exist For A Reason by ynniv on Wednesday May 02, 2012 @05:00PM (#3921175)
With the comma first style, that bug would never have been introduced. Neat, huh?

If you run any syntax checking or minification tools, this will be immediately obvious. If you test your site in IE at all, this will be immediately obvious. If you record JS errors on your site, this will soon be obvious. If you record any kind of usage statistic, this will eventually be obvious.

Take it from someone who has experimented with cutesy formatting in the past[1]: you don't need to use cutesy formatting to solve this problem.

[1 | You can end class declarations with _:0} instead of a bare } to avoid the trailing comma issue. ]

Re:Best Practices Exist For A Reason by mustpax on Wednesday May 02, 2012 @08:33PM (#3921856)
Prevention > Detection by Developer > Detection by Tester > Detection by Customer.

Having mechanisms in place to catch programmer errors is no excuse for adopting practices that make programmer errors more likely.

Re:Best Practices Exist For A Reason by ynniv on Wednesday May 02, 2012 @11:22PM (#3922233)
Two of the tools that I mentioned are in the "prevention" category: syntax checkers and minifiers. The full enumeration is just a sanity check. If coding style is the only thing keeping your product from being broken, you're doing something else quite wrong.
Re:Best Practices Exist For A Reason by btilly on Wednesday May 02, 2012 @05:36PM (#3921339)
Indeed the link I gave demonstrates how the right IDE also solves this problem. The fact that there are many ways of solving the problem does not mean that it isn't a real problem that formatting can help address.
Re:Best Practices Exist For A Reason by ynniv on Wednesday May 02, 2012 @05:54PM (#3921403)
It is a real problem. Formatting can address it. That doesn't mean that formatting is the best solution.
Re:Best Practices Exist For A Reason by taligent on Wednesday May 02, 2012 @05:58PM (#3921420)
It means that there are ways of solving the problem that don't involve rewriting the code in a way that initially will confuse 99.999% of other developers.

And it is important in our industry to write MAINTAINABLE code.

Re:Best Practices Exist For A Reason by mattbriggs on Friday May 04, 2012 @12:27AM (#3927014)
if comma first confuses a dev more then half a second or so, they really aren't that good. First time I saw comma first was from a DBA about 10 years ago who swore by it, and it has been my go to technique for writing maintainable code in languages where you end up with huge comma separated lists.

I freely remove, add, and move things to the bottom of my js classes without ever hitting trailing semis, or hitting a missing semi. I think that is more maintainable then the alternative

Re:Best Practices Exist For A Reason by mark_story on Wednesday May 02, 2012 @09:27PM (#3921985)
You can also tell tools like JsHint to look for this common error, and not have to use _:0 everywhere.
Re:Best Practices Exist For A Reason by ynniv on Thursday May 03, 2012 @12:28AM (#3922382)
That's not what I meant... I must have used that example in a confusing manner. I do not recommend using syntax gimmicks.