Earlier 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…
What's harder, finding an extra trailing comma, or finding a missing semi-colon in a JavaScript file that contains no semi-colons?
Best Practices Exist For A Reason
61–70 of 105 posts
Re: Best Practices Exist For A Reason
#62Earlier quoted context omitted.
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.
I think I might have explained myself poorly. I'm suggesting using separate var statements for each assignment, e.g.: 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.
x = {[
{ id: 1, data: 0 },
{ id: 2, data: 0 }
],
[
{ id: 3, data: 0 },
{ id: 4, data: 0 }
]}Re: Best Practices Exist For A Reason
#63Earlier quoted context omitted.
That example gist went a long way towards convincing me of isaacs' comma prefix style. 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 pants and see if it helps. Thanks for the link!
That example gist went a long way towards convincing me of isaacs' comma prefix style. What convinced you? I read it and saw something wildly different, which is best reserved for a good reason. The reason appears to be visual recognition of delimiter mistakes that the parser will catch anyway. The gist contains examples of various mistakes in both styles. Most of the errors are syntax error which will be immediately…
return
{ a : "ape",
b : "bat"
}
The error here has no relation to the commas.Re: Best Practices Exist For A Reason
#64Earlier quoted context omitted.
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…
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
#65First, Isaac Schlueter isn't advocating against best practices with ASI. He's advocating for an alternate best practice that you disagree with. In that very article he suggests an alternate place to put the necessary semicolons. Second, the CouchDB thing isn't because of a lack of best practices, it's because the wrong best practices were misapplied. And in the end, its use of best practices prevented it from severel…
The best practice is to use a purpose-built password algorithm like bcrypt. Algorithms like SHA1 and MD5 are designed to run fast; even with salts they can be cracked by massively parallel hardware like a room full of GPUz.
Re: Best Practices Exist For A Reason
#66This is my love/hate relationship with JavaScript. There is often more than one "correct" way to do things and there is a lot of disagreement in the JS community about what way is "best". Contrast this with Python where the overarching rule is there should be one, and preferably only one, obvious way to do things.
Re: Best Practices Exist For A Reason
#67Earlier quoted context omitted.
"Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert?" You're framing this as a disagreement between equals. It is not. There are degrees of expertise. (Total lines of production code * amount of usage) is a reasonable approximation, and those who rank highest on this scale are overwhelmingly in favor of requiring semicolons. If Carmack and Torvalds were in agreement o…
You can think about the effect of coding style instead of letting the experts think for you. If you are doing a Topcoder round, then the random Topcoder user's advice is probably better than Carmack's. Carmack or Torvalds would probably tell you to use a variable name that gives a lot of information about its purpose, so that other people will find it easier to read your code. The Topcoder user might tell you to use…
Right, because what could those experts possibly have to teach you? Fuck that intellectual crap, brogrammers are here to crank out some code yo! Just because those dinosaurs have spent "thousands of hours" studying and trying out different programming styles and concepts means I should listen to them? This is the internet age man. Some guy in a github comment told me different and github is cool.
It's like those functional programming professors who try and talk about how continuation passing style was a bad road to go down because of maintenance problems and how difficult refactoring and just reasoning about code becomes in large systems.
Fuck that egghead noise, node.js has callbacks and node is how you get webscale.
I'm right with you bro!
Re: Best Practices Exist For A Reason
#68The 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…
No.
Here's one idea: perhaps everyone's opinion is not equal on every subject. Perhaps by looking at the opinions of respected accomplished people who have garnered the respect of other respected accomplished people you can being to see who's opinion should get more weight. This is the process that came up with the very ideas of things like "engineering" and "quantitative".
I know we love the young upstarts disrupt the old way of thinking meme. That's why you framed it this in that way with the folks vs the traditionalists. You might want to remember that historically the young upstarts have been wrong 99% of the time. That's why it's news when they are right.
"One man's best practice is another man's anti-pattern"
And in the vast majority of cases, when you ask that question about a specific problem: One of those men is wrong. Even if they're both smart. But how to tell? If a huge number of other smart and experienced people have been convinced by one of them ... well I'd go with that guy. You won't be right all the time but it's the best system we've come up with so far for things that don't conform to double blind placebo controlled studies or mathematical proofs. It literally is the best way to be right most often.
Re: Best Practices Exist For A Reason
#69The 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…
The root problem is that we still don't know how to disagree when two sides look at the same set of data and believe two different things. We allow ourselves to descend into tribalism and assume the worst of each other. If you look at the language Tom objects to the most, it's language Isaac uses that promotes this tribal attitude that the other side doesn't have your best interests at heart, and questions their moti…
The tribal attitude is the enemy of this process for sure, and humans are very prone to that attitude but that doesn't mean you can't still find the answer more likely to be right.
Re: Best Practices Exist For A Reason
#70This is my love/hate relationship with JavaScript. There is often more than one "correct" way to do things and there is a lot of disagreement in the JS community about what way is "best". Contrast this with Python where the overarching rule is there should be one, and preferably only one, obvious way to do things.
http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces
The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. For new projects, spaces-only are strongly recommended over tabs.
Function names:
...
mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.