Proposal for a scientific look at C style choices

Mark A Terribile mat at mole-end.UUCP
Mon Jan 2 13:33:24 AEST 1989


In article <1045 at ns.UUCP>, ddb at ns.UUCP (David Dyer-Bennet) writes:
> :Likewise, I generally write
> :
> :	if(    a->op == XNES_step
> :	    && a->size <= XNES_bufsize
> :	 ||    a->op == XNES_fix
> :	    && a->size + a->leftover <= XNES_bufsize )
> :	{
> :		. . .
> 
> However, your strange idea violates one of MY basic concepts of code
> formatting: indentation is something that takes place between the left
> margin and the first character on the line, NOWHERE ELSE.

Hmm.  Do you mean that you have never written

#if ...

#  if ...
. . .
#  else
. . .
#endif

Yes, I am breaking my own rules about tabstop indents!  It seems so desirable
to keep the preprocessor stuff visible at the begining that I'm willing to
go to two-space indents.  On the other hand, I read the preprocessor stuff
about one thirtieth (numeric value generated by scientific hand waving) as
often as I do the code which is compiled into object, and so I am willing to
take a slight cost in readability.

My criterion is communication: how well does the typographical layout of the
code on the page communicate the organization of the code?  (See the example
on p. 23 of Kernighan and Plauger, *The Elements of Programming Style*.)

Does the example first given carry the principle too far?  Having waded
through thousands of lines of code whose lines were broken where nroff would
break them and whose authors evidently thought more levels of parentheses
were better ways of communicating to the reader than typography, I think that
the principle is NOT carried to far, if only because it serves to inspire
people working with me to improve a little.  As it might have been written:

	if(((a->op==XNES_step)&&(a->size<= XNES_bufsize))||((a->op==XNES_fix
		)&&((a->size+a->leftover)<=XNES_bufsize)))

(Ok, even nroff wouldn't have put the ``)'' at the beginning of a line.  I
have seen it done by programmers, however.)

> (... this is ONLY my opinion.  If this had been objective reality, you would
> have done it my way and we wouldn't be having this discussion.)

You better *smiley* when you say that, son ;'[  ;^}
-- 

(This man's opinions are his own.)
>From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list