NOTE: This document may be circulated or quoted from freely, as long as the copyright credit is included.
Ever since the "structured revolution" of the 1970s we've paid close attention to the readability of source code. Programs that are hard to read are expensive and error-prone to maintain. Enlightened courses and textbooks present criteria for white space, indentation, alignment, commentary, data naming, and other aspects of readability. We expect programmers, from beginning students to experienced superstars, to comply with the spirit of those criteria.
It's surprising and distressing, therefore, that leading professional publications and trade journals continually undermine good practice in source code formatting. Particularly egregious offenders include:
Unreadable code in periodicals is often the result of trying to jam a program listing into a 3-column page layout. Each column is about 2 inches wide, enough for just 26 positions of monospace type. Squeezing code into 26-position lines may work for uncommented assembly language, but not for non-trivial code in any higher-level language.3 Imagine writing a program using an editor or a compiler that limited the line size to 26 characters!
Here's a recent example:
class UseHello {
public static void main
(String[] args) {
HelloWorld myHello =
new HelloWorld();
myHello.printHello();
}
}
Communications of the ACM, vol. 44, # 10, p. 130 |
Worse yet is this one, where an identifier has gotten hyphenated:
Communications of the ACM, vol. 45, #2, p. 12 |
A wider 2-column (3½ inch) format is usually satisfactory, but it can yield hard-to-read, even illegal code when the author/editor fails to pay attention to the line lengths. This one not only violates indentation but also breaks string literals:
Java Developer's Journal, vol. 2, #4, p.55 |
As a result of these strange practices:
I still expect readable code from students and project-team members, and write readable code myself. |
Magazine editors: NOTE Three-column format is inappropriate for material containing program source code. If you must set the text in three columns, then move the code examples out to figure boxes. And no matter what line length you choose, make sure the line breaks occur in logical (or at least legal) places. Your publication is about computer programming. Have a competent computer programmer proofread it. |
1 -- Overheard at a 1965 SHARE meeting following a discussion of compatibility
prolems in IBM's OS/360. Return to IDI Home Page
Last modified January 28, 2002
2 -- Source-code misformatting is far from the only editorial problem plaguing that
once-prestigious publication. Hardly an issue lacks some gaffe in grammar, usage, terminology,
or fact.
3 -- The C/C++ Users Journal also relies on 3-column format for
some material. However, the editors pay more attention to the line breaks,
use a smaller font, and are willing to switch to two columns in the middle of
an article when the material demands.
4 -- Even if the students were able to decipher the code, what message is
conveyed to them by a respected international publication violating practices their
instructor has told them are important?
Return to Technical articles