in reply to Logical expression style
Consider the fragment:
This is certainly readable, but to recognize what the expression is (i.e., is it a conjunction, disjunction, or a hybrid) requires reading to the end of the line. If it's a long line, this slows down my scanning pattern by making me read further to the right.if ( A && B )
Now consider
Equally readable, but easier, in my opinion, to recognize when quickly scanning code.if ( A && B )
Formatting for recognizability also forces a non-obvious change in indentation style. I'll write
if the expression is short enough to fit on one line, but will writeif ( A && B ) { ... }
if the expression needs to be broken across lines. The reason? It's easier to quickly pick out the scope when scanning code. If I were to be consistent, and format the fragment asif ( A && B ) { ... }
it would still be readable, but a bit harder to quickly recognize.if ( A && B ) { }
|
|---|