Subject: Re: Time to update KNF?
To: Dave Sainty <firstname.lastname@example.org>
From: Mike Cheponis <mac@Wireless.Com>
Date: 01/19/2000 09:15:14
> That said, I prefer to get as much out of the 80 columns as possible,
> and use the frowned-upon 2 space indenting :) Not to indent more
Eventually, I hope we can dispense with 80 characters (like the Windows
world has already done) but for all the reasons mentioned here, I'm not
advocating changing that.
As to 2-4 vs 8 spaces, I trudged over to Stanford yesterday and dug up the
original 7-page article by Prof. Shneiderman and students Miara, Musselman,
and Navarro from the University of Maryland.
There are other results from previous work mentioned. For example, subjects
were given two programs, one indented and one not, and were asked to fix a
bug. The data from this experiment suggested that as program complexity
increases, program comprehension is aided by indentation.
Novices and experts were tested. About half of the article is devoted to
experimental setup and accounting for biases and experimenter-induced errors;
it seems to me as if these sources of error have been well-controlled.
Here is the "Discussion" section from the next to last page, followed by
the "Conclusion" section:
The results indicated that the level of indentation has a
statistically significant effect on program comprehension and that
deeper indentation could become more of a hindrance than an aid.
The level of indentation that seems to produce optimal results in
comprehension is between 2 and 4 spaces; as the number of spaces
increase, the comprehension level decreases. The decreasing level of
comprehension might be attributed to the fact that as the nesting level
in a deeply indented program (i.e., 6 spaces of more) increases, the
program is shifted so far to the right of the page that scanning
becomes difficult. In the nonblocked , 6-space version, it became
necessary to continue statements on the next line when the nesting
level brought the text to the 80-column limit of the compiler. With
2-4 space indentation levels, however, the program is more compact and
the control blocks do not become obscured by increased nesting levels.
Novices showed great displeasure with the nonindented version of the
program and had significantly lower scores on that version. Their
best overall performance was with the version that they rated the
least difficult (2 spaces). Novices seemed more concerned with the
program style than whether it would run. We feel this bias is a
result of the requirements placed upon the novices in their
programming class; they were required to write programs that were
indented, spaced, and commented. Also, most Pascal textbooks,
including the one being used by the subjects' professor, show programs
that are indented. Novices consider indentation to be a "good"
programming practice and the lack of indentation produced negative
feelings toward the program comprehension task as noted by the
comments on the quiz. These negative feelings toward the nonindented
versions explain the quiz results.
Experts, on the other hand, did not express any negative opinion
towards the nonindented version of the program. We feel that
experienced programmers will generally approach a comprehension task
without much consideration of the style in which the program was
written. Very few comments were received by the experts when the
experiment was implemented.
Fifty percent of the novices and 62 percent of the experts with
nonindented programs marked their listings to connect the control
blocks. This result indicates that some form of indentation is needed
to clearly distinguish control segments in the program. However, when
the program is deeply indented, control blocks might not be clearly
identifiable; some subjects marked their 6-spaced version to reflect
the control-block structure.
The blocked and nonblocked styles of the program yielded no
significant differences between the experts or the novices. We are not
sure why this result occurred because we expected a significant
difference in comprehension with the type of blocking used for control
structures. It may be possible that comprehension scores for a longer
and more complex program would show a greater difference with the type
of blocking used for the control structures.
Overall, experts did better on the comprehension task and rated the
program less difficult than the novices. These results were
reassuring because we expected the experts to do better and to rate
this type of task less difficult than the novices.
Finally, the combined results of the expert and novice subjects showed
the highest mean scores in the 2-space indent programs. It is
interesting to note, however, that the 6-space indent programs were
rated as least difficult to use. We feel that this result occurs
because programmers find a deeply indented program visually pleasing
since it seems to spread out neatly the constructs of the language.
However, when a comprehension task is assigned, this exaggerated
spacing causes problems when control blocks become harder to locate
with deep indentation, thus resulting in lower scores. The fact that
some subjects marked their 6-space version with block-connecting lines
provides evidence that control blocks do become harder to distinguish
with deep indentation.
This experiment tested the effects of the indentation on program
comprehension. The levels of indentation we tested (0-6 spaces) gave
strong results favoring 2 or 4 spaces. We believe future experiments
should employ the metric of program comprehension, and that nine
indentation levels (0 to 8 spaces) be studied. It would be
interesting to see how significantly comprehension would be affected
beyond the 6-space indentation level.
In summary, we conclude that some indentation does aid program
comprehension. From our results, we suggest that the optimal level of
indentation is 2-4 spaces. No indentation produced significantly
lower mean scores and the subjects found working with this program
difficult. We conclude that in a large program, no indentation would
be a real hindrance and very difficult to use. The same is true for
overly indented programs. With large programs, overindentation make
make it difficult for the user to easily scan the program for a
particular structure block because the program statements are spread
across the page instead of being a compact format. Although no
significant difference were found between the blocked and nonblocked
program styles, we suggest that other blocking styles may aid program
comprehension and increase user satisfaction. In any case, the
blocking style should be consistent throughout the program so that
users can easily find the statement or statement segment that they are
trying to locate. In closing, we agree with Kernighan and Plauger [In
the Elements of Programming Style] who stated that "Indentation must
be done carefully, however, lest you confuse rather than enlighten."
From all of these data, since the highest comprehension scores were noted
with 2-space indents, I, once again, believe that KNF should be
modified to use 2-space indents.