C Programming Style -- New thought
Jay Freeman
freeman at spar.UUCP
Wed Jul 24 11:13:36 AEST 1985
References:
[Fools rush in where even the line-eater fears to tread]
I find that one of the things that most affects my personal choice of
program-formatting style is the number of lines on the console I work at.
Most of my C coding is done sitting in front of old-style displays of 24 by
80 lines. I find it very valuable to be able to see all of a function (or
at least all of a {} block) at once: Therefore, I favor styles such as
if( (foo = bar( baz )) != ERR ) { ... /* style A */
over
foo = bar( baz ); /* style B */
if( foo != ERR ) { ...
when useful to save lines. If the lines saved by using style A instead of
style B, make the difference between having all of a block on screen at once
and not; then I consider the additional complexity of style A to be worth it.
(And of course, there is ...
foo = bar( baz ); if( foo != ERR ) { ... /* style C */
which I mention for completeness but consider a loser over (under?) style A.)
My point is not to tell you all how to do it, but merely to emphasize that
screen size imposes a tradeoff among different sources of
incomprehensibility.
A related issues is whether it is "worth it", in the same tradeoff, to have
an extra line for '{' or for '}'. (My personal opinion is "no" for the
former and "yes" for the latter.)
Incidentally, I avoid printouts wherever possible in developing code: I use
them only when I cannot get to a terminal for some reason -- I cannot
imagine circumstances in which my preference would be the other way around.
(Well, maybe 300 baud ...)
--
Jay Reynolds Freeman (Schlumberger Palo Alto Research)(canonical disclaimer)
More information about the Comp.lang.c
mailing list