C bites / programming style

Dave Bloom dave at andromeda.UUCP
Tue Sep 10 00:35:06 AEST 1985


In article <735 at umd5.UUCP>, zben at umd5.UUCP writes:
> 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.

I have seen programs written in this style, and find them terribly confusing
to read because there are just too many levels of indentation to the eye. Also,
if you are working on a bogus editor, indenting with anything other than tabs
becomes a chore. I prefer:

	if(some condition) {
		A statement;
		Another Statement;
		Some Garbage;
		}
	while(another condition) {
		etc;
		etc;
		}

This does a few things: For starters, the opening brace does not occupy a
line of its own, which makes the code a lot more compact from a visual point
of view. 2) The closing brace is in line with the indented code, and serves
as a terminator much as a ';', 3) The closing brace really shouldn't be in line
with the if, because it is PART of the if statement and should be represented
as such. You should be able to read down the program and see each statement
on its own indentation level without the clutter of closing braces.

-- 
-------------------------------------------------------------------------------
      allegra\					       Dave Bloom
      harvard \ pyramid\
       seismo  \  pyrnj >!andromeda!dave         HOME: (201) 868-1764
     ut-sally   >!topaz/			 WORK: (201) 648-5083
       sri-iu  /
ihnp4!packard /		           "You're never alone with a schizophrenic...."



More information about the Comp.lang.c mailing list