Thank god for that guy. I didn't want to type all of that up on my phone. You both do one thing any other JS dev will hate you for though: Allman Style indentation.
var x = 1;
function allman()
{
x++;
}
The { on another line is BAD in scripting languages! Because one could comment out or delete a line accidentally, and it's still valid code throwing no errors:
var x = 1;
//function allman()
{
x++;
}
On the other hand, this would vomit all over:
var x = 1;
//function allman() {
x++;
}
This is why KNF style (shown above) is preferred for JavaScript. The only language I can think of off the top of my head where Allman style is the preferred common-practice is C#. But you'd have less problems in any compiled language like that, because the compiler is going to watch your syntax pretty closely. EDIT: Banner style is used a lot too.
I am positive this is going to be heavily disagreed with...but I really like Allman. :)
I like it for two reasons:
First, I just like the Gestalt of it. I find code a lot more scannable when the squigglies line up nicely, especially in languages like JavaScript where you can have a ton of nesting.
Second, it forces me to write my code in such a way that whitespace becomes irrelevant. I can never get away with something like this:
return
{
foo: "foo"
};
And so I am forced to name things appropriately, which I prefer.
But I completely understand that I am in the minority on this, and I would never attempt to fight this battle. :)
2
u/stevekwan Feb 23 '13
Wow! A great peer review and tons of good advice here. Thanks mirion, I will definitely take these into account.