std::cerr << "The following execution is " <<
"probably best placed on multiple lines. <<
std::endl;
or, in another case:
if (the_job_is_finished &&
there_are_no_jobs_left &&
(timer > 10))
{
...
}
Novices might be more acquainted with this formatting:
std::cerr << "I am a novice programmer, and"
<< " I am still learning the best-practices"
<< " for programming style."<< " I am still learning the best-practices"
Which better serves the paradigm of programming maintenance? I cannot contend against the aesthetics of the second, amateurish attempt. The alignment of the dual brackets is nothing if not captivating. But do they serve the purpose of easing the reading of the code? No. To demonstrate this inefficiency of this method, consider reading the code, one line at a time.
std::cerr << "I am a novice programmer, and"
Great- a line is being printed to stderr.
<< " I am still learning the best-practices"
...Wait- what does that "<<" mean- I've got to look at the previous line... Okay, now I see- we're continuing output.
The "..." indicate a momentary interruption to the left-to-right, top-down flow of code. This momentary interruption is significant because it requires the reader to investigate context in code that he has already read. This extra effort could be avoided with proper style.
Now, consider the more efficient and excellent way:
std::cerr << "The following execution is " <<
A line is being printed to stderr and it appears the next line will continue the output.
"probably best placed on multiple lines. <<
Clearly this line is a continuation from the previous line of code.
Hundreds of years of typesetting have used hyphenation to indicate when a word extends beyond the line in which it commenced. I do not expect to ever see the follow
-ing in a book. The practice of prefixing multiple line statements with an operator is akin to prefacing a line with a comma, or a hyphen- it's bad practice in typesetting- and it's bad practice in coding.
0 comments:
Post a Comment