The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…
Best Practices Exist For A Reason
41–50 of 105 posts
Re: Best Practices Exist For A Reason
#42Earlier quoted context omitted.
To play at devil's advocate, please don't. Otherwise you should have written your comment like this: To me , consistency is important . All of my codebase is traditional comma postfix , so I'll keep using that ; however , maybe with some new projects I'll try on the comma prefix [...] ... using typography in a typographically sensible way is far more important to readability than an arbitrary "consistency" of punctat…
Why does nobody ever mention the obvious solution? Separate var statements. They're always correct, they copy without any editing, and the "var"s line up to show that it's a block of assignments the same as commas or whitespace.
var foo = 1,
bar = 2
baz = 3
In 90% of the cases the code will run the same whether or not there is a comma on line 2, but in the other 10% you will get burned in odd ways now that `baz` is a global variable.Re: Best Practices Exist For A Reason
#43Earlier quoted context omitted.
Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…
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 experiment…
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
#44Re: Best Practices Exist For A Reason
#45The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…
Stylistically, I side with the no semicolon people. Grammatically they're redundant.
Pragmatically, if you ever find yourself saying "read this enormous, hard to read spec just so you can identify the three or four edge cases that will burn (yet remain statistically likely to commit)" you are on the losing side of history.
Basically, it's preposterous to have reasonably smart people seriously argue that the option that is least user friendly and most likely to cause pain down the road is the best one out of a sense of misguided spec puritanism.
Re: Best Practices Exist For A Reason
#46Earlier quoted context omitted.
Why does nobody ever mention the obvious solution? Separate var statements. They're always correct, they copy without any editing, and the "var"s line up to show that it's a block of assignments the same as commas or whitespace.
You can only put var at the beginning of variable declarations, but there are many other places that commas are used as a separator. So that "solution" doesn't apply in general.
var a = 2; var b = 4; var c = { blah: "whatever" };
Leaving out a semicolon has no effect. They can be copied without any fuss. It's easy.
Re: Best Practices Exist For A Reason
#47Good advice comes with a rationale so you can tell when it becomes bad advice. If you don't understanding why something should be done, then you've fallen into the trap of cargo cult programming, and you'll keep doing it even when it's no longer necessary or even becomes deleterious.
source: http://blogs.msdn.com/b/oldnewthing/archive/2009/11/04/99170...
Re: Best Practices Exist For A Reason
#48The real question is why anyone takes obviously wrong artifacts in JavaScript like omitting semicolons and flagrantly wrongly designed this binding seriously. This isn't an issue of best practices or personal preferences, it's aspects of a ubiquitous language that are simply and unequivocally broken.
The reason people talk about omitting semi-colons in JavaScript is because they don't think that feature is unusable--they clearly think it's better than adding semi-colons everywhere! When reasonable people disagree like that, the situation is rarely simple and clear-cut.
Now, perhaps you could reasonably argue that the behavior is unfortunate. But you can also reasonably argue the converse. And, most importantly, it isn't immediately clear who is correct.
Re: Best Practices Exist For A Reason
#49Earlier quoted context omitted.
Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…
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 experiment…
Re: Best Practices Exist For A Reason
#50Earlier quoted context omitted.
Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…
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 experiment…