Better C Bracing Style

utzoo!decvax!harpo!ihps3!ixn5c!pcl utzoo!decvax!harpo!ihps3!ixn5c!pcl
Fri Oct 29 12:02:38 AEST 1982


I thought I might share with you all an interesting anecdote brought to
mind by Steve Wagar's suggested bracing convention of

if(conditional){statement;statement;statement;}

In my first year of grad school, I took the (required) data structures
course.  In addition to the obvious things such a course might cover, at
this school it was also supposed to cover some elements of structured
programming.  Well, the professor I had preferred a style quite similar
to Steve's above:  embedded spaces were allowed, but you were to
continue on the same line (card, actually) until no more words would
fit, and only then move to a new line.  The only exception to this was
starting a new procedure.  The advantages he saw were somewhat different
from those described by Steve:

1.	You used fewer cards for your program.  Besides being good for the
	environment, this made it less likely that you would drop your deck.

2.	You were much less likely to get two cards reversed and not notice,
	which is so easy to do with that "one statement per line" style.

3.	Your program would compile faster, thus charging you less per
	run while debugging your program.  [Students had a fixed dollar
	allocation per semester for computer use in each course.]

4.	You would be charged less, since fewer cards were read on each run.

5.	You would be forced to write your entire program up ahead of
	time, and not try to compose "at the keypunch" (which we all
	know is a terrible practice).

When I was so perverse as to insist on starting each statement on a new
card, and *indenting* those statements to reflect the block structure,
he (reluctantly) agreed not to take off any points!  [By the way, I had
learned these nasty habits in the three previous years of working in
BASIC - mostly from maintaining code that didn't follow them.]

This was not that many years ago, either!  I think I'll leave the school
and professor un-named, except to say that the professor was a senior
faculty member, whose earlier work is cited in Knuth.  Also, the
teaching assistant was Mark Horton;  I think it was even harder for him
trying to help the others in my class, than it was just being a member
of that class.

			Paul Lustgarten
			Bell Labs - Indian Hill



More information about the Comp.lang.c mailing list