When making on-the-fly decisions on breaking lines, I try to consider
readability and
recognizability. 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.
Consider the fragment:
if ( A &&
B )
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.
Now consider
if ( A
&& B )
Equally readable, but easier, in my opinion, to recognize when quickly scanning code.
Formatting for recognizability also forces a non-obvious change in indentation style. I'll write
if ( A && B ) {
...
}
if the expression is short enough to fit on one line, but will write
if ( 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 as
if ( A
&& B ) {
}
it would still be readable, but a bit harder to quickly recognize.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.