A question of style

Chip Salzenberg chip at ateng.com
Wed Dec 13 06:54:12 AEST 1989


According to amull at Morgan.COM (Andrew P. Mullhaupt):
>According to chip at ateng.com (Chip Salzenberg):
>> The general rule I adhere to most strictly is:  "Repetition is evil."
>> The expression "c=getchar(), c!=EOF" is harder to read than
>> "(c = getchar()) != EOF" for [this] reason.
>
>Isn't it possible that in some places repetition can increase
>readability?

Of course.  Any style rule, taken to the extreme, can be counterproductive.
But elimination of redundancy leads automatically to several good
programming practices, especially factoring.

True, readability is only one issue.  But small-scale and large-scale
readability are sometimes at odds.  For example, if you write a program that
consists entirely of simple, understandable modules, that's fine; but if the
functions of the program are factored badly enough, the source will be too
big to understand, and will therefore be unreadable on the large scale.

I think that the best measure of readability is not lines of code per unit
time, but percentage of program per unit time.  If a routine takes ten
minutes to understand, that's bad; but if that routine is one tenth of the
program, things are looking up.

>I'd rather break some expressions into more than one part just to keep
>the lid on the complexity, even if I need to see the same thing twice
>in a row.

Actually, the creation of temporary variables is a classic way to eliminate
repetition in program code.  I constantly use them that way myself.
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip at ateng.com> or <uunet!ateng!chip>
	  "The Usenet, in a very real sense, does not exist."



More information about the Comp.lang.c mailing list