Closed prettycode closed 10 years ago
Super agreed, maybe you could add this rule to the guide?
I think a one liner if (err) { throw err; }
is fine, but definitely not when involving more than one or two statements (such as if (err) { next(err); return; }
), and definitely not when involving an else
statement.
Let me know if you can add this or I'll get to it at some point
What about a general Bad, Good, Even Better pattern instead of just Bad and Good?
Let me know if f4555d14ca4ab4bd8ed7da344310101092965b1a addresses your concerns :)
Perfect. Thank you :-)
Under Conditionals, you demonstrate the following, below, as "Good":
Yes, the practice of using brackets when they're optional is indeed good.
Aside from that, however, I don't believe opening and closing curly brackets should ever be on the same line, as a rule. It encourages poor readability.
When you're visually scanning code, this is much harder to parse:
Than this:
Or even this:
Density is not a good thing.
Keeping code terse and line numbers down can sometimes be counter-productive. Same-line opening/closing brackets give developers the illusion of a code block having less logic in it than it actually has.
If I see a method with three lines as I'm scanning, I will likely perceive the complexity to be less than if I see a method that does the exact same thing but is nine lines. The risk is that other developers will come along and stuff more logic into that method with three lines than the one with nine. Code blocks with same-line open/close brackets end up growing larger in complexity, discouraging abstraction and separation of concerns.
White space, on the other hand, is a good thing.