3 ms·
Everyone has their own style. As one controversial example, some programmers do this if (condition) singleStatement; Their POV is less lines = bette
by greggman 15y ago
Everyone has their own style. As one controversial example, some programmers do this
if (condition)
singleStatement;
Their POV is less lines = better.
And others do this
if (condition) {
singleStatement;
}
Their POV is defensive programming and or consistency is better.
Similarly, some programmers prefer
var a,
b,
c = 3;
Because less typing = better. Others prefer
var a;
var b;
var c = 3;
Because they prefer consistency and defensiveness. Deleting any line doesn't effect the others where as in the 1st example, delete the first or the last line and other lines have to change (which is funny since that means MORE typing).
Yet another example
if (condition) {
statement;
statement;
}
vs
if (condition)
{
statement;
statement;
}
Some prefer the first because it's shorter. Others prefer the second because it's consistent and keeps the blocks separate and movable.
IMO one vs the other is not a pattern vs anti-pattern. It's a style decision. Me, I'm on the consistency and defensive programming > shortness of typing side of this fence. It's disheartening to see some self appointed JS gurus claim their 'style' is better when clearly it's just 'style'.
- tszming 15y agoBecause of the implicit semicolon insertion in JavaScript, it is better to place the curly brace next to the condition IMHO. After all, I agree the most important thing is to be consistent.