4 ms·
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 immediatel
by ynniv 15y ago
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. ]
- btilly 15y agoIndeed 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.
- ynniv 15y agoIt is a real problem. Formatting can address it. That doesn't mean that formatting is the best solution.
- taligent 15y agoIt 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.
- mattbriggs 15y agoif 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
- mustpax 15y agoPrevention > 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.
- ynniv 15y agoTwo 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.
- mark_story 15y agoYou can also tell tools like JsHint to look for this common error, and not have to use _:0 everywhere.
- ynniv 15y agoThat's not what I meant... I must have used that example in a confusing manner. I do not recommend using syntax gimmicks.
- mark_story 15y agoYou can also tell tools like JsHint to look for this common error, and not have to use _:0 everywhere.