C bites / programming style

zben at umd5.UUCP zben at umd5.UUCP
Sat Sep 7 12:11:27 AEST 1985


In article <209 at 3comvax.UUCP> mikes at 3comvax.UUCP (Mike Shannon) writes:
 
>With regard to changing
>	if(condition) {		 |		if(condition)
>		s1;		into			{
>		s2;		 |			s1;
>	}			 |			s2;
>				 |			}
>[the idea is to indent the braces so that they are in the same column as
>	the statements they enclose]

Actually, I prefer:

   if (condition)
    {
      s1;
      s2;
    }

If I had to rationalize, I would say that the { and } are intermediate in
level between the mainline code and the controlled statements, and that their
indenting reflects this intermediate status.  Also, you can draw lines on the
listing between the brackets and manually verify nesting status.  This seems
very useful, as the C compilers I have used don't seem to be very good at
giving meaningful diagnostics in this case.

(Can you say "pathological"?  I *knew* you could!)

Also note, indent by one and then two, so each level of indenting takes only
three columns.  This means you can program a more complicated routine before
you start running out of space on the right.  You shouldn't be programming
routines that are that complex?  Silly person, this is C!  Any language in
which *(*(*(*(*(int ()(*)()(*)))))) is a legal declaration can't put much
emphasis on clarity, can it?  (I know, religious statement...).

Guess it's a good thing my terminal doesn't do tabs, or I would be locked
into that silly "every 8" standard and writing twice as many functions as
I had to...
-- 
Ben Cranston  ...{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben  zben at umd2.ARPA



More information about the Comp.lang.c mailing list