Not to go against the grain or anything (or disagree with Douglas Crawford), but why is this considered the de-facto JS coding pattern:
[code=javascript]
// The "Crawford" pattern
function myFunc() {
var a = "Hello";
var b = "world";
for (var i = 0; i < 3; i++) {
alert(a + " " + b);
};
};
[/code]
When (to me) this is much clearer to read:
[code=javascript]
// The RMWChaos pattern ;-)
function myFunc()
{
var a = "Hello";
var b = "world";
for (var i = 0; i < 3; i++)
{
alert(a + " " + b);
};
};
[/code]
In both cases, the code will be the same length when minimized, and they are syntacticly identical to one another. However, the second version just seems infinitely easier to read (to see where blocks begin, identify conditionals, etc.) and, therefore, easier to modify, bug-check, etc. (IMHO).
Am I alone here? Maybe this is just my bias from working with BASIC and COBOL for so long, and after a while I will see the first version as easier to read ... perhaps.
Oh, and what's the big deal about using spaces to indent (4, 8, 16, etc.) vs. Tab? So what if Tab lengths are not standardized between programs...as long as they are indented?
[code=javascript]
// The "Crawford" pattern
function myFunc() {
var a = "Hello";
var b = "world";
for (var i = 0; i < 3; i++) {
alert(a + " " + b);
};
};
[/code]
When (to me) this is much clearer to read:
[code=javascript]
// The RMWChaos pattern ;-)
function myFunc()
{
var a = "Hello";
var b = "world";
for (var i = 0; i < 3; i++)
{
alert(a + " " + b);
};
};
[/code]
In both cases, the code will be the same length when minimized, and they are syntacticly identical to one another. However, the second version just seems infinitely easier to read (to see where blocks begin, identify conditionals, etc.) and, therefore, easier to modify, bug-check, etc. (IMHO).
Am I alone here? Maybe this is just my bias from working with BASIC and COBOL for so long, and after a while I will see the first version as easier to read ... perhaps.
Oh, and what's the big deal about using spaces to indent (4, 8, 16, etc.) vs. Tab? So what if Tab lengths are not standardized between programs...as long as they are indented?
Comment