note
dws
When making on-the-fly decisions on breaking lines, I try to consider <b>readability</b> and <b>recognizability</b>. They're different beasts, though they're often conflated. Readability is about being able to grok the entire expression. Recognizability is the ability to classify the expression when doing a quick scan through the code. When scanning quickly, my eyes focus to the left.
<p>
Consider the fragment:
<code> if ( A &&
B )
</code>
This is certainly readable, but to <i>recognize</i> 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.
<p>
Now consider
<code> if ( A
&& B )
</code>
Equally readable, but easier, in my opinion, to recognize when quickly scanning code.
<p>
Formatting for recognizability also forces a non-obvious change in indentation style. I'll write
<code> if ( A && B ) {
...
}
</code>
if the expression is short enough to fit on one line, but will write
<code> if ( A
&& B )
{
...
}
</code>
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 as
<code> if ( A
&& B ) {
}
</code>
it would still be readable, but a bit harder to quickly recognize.
<p>
181308
181308