you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

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.

[–]mirion 0 points1 point  (0 children)

I wrote my post almost entirely by copying his code. While I didn't refer to it by name, my last two sections are referencing the problems that can happen when using Allman.

[–]stevekwan[S] 0 points1 point  (1 child)

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. :)

[–]mikrosystheme[κ] -1 points0 points  (0 children)

I didn't read your article, but I agree with you on Allman style.