C bites / programming style

Adam V. Reed adam at npois.UUCP
Thu Sep 12 02:18:54 AEST 1985


joel "vo" plutchak {allegra,ihnp4,seismo}!uwvax!uwmacc!oyster writes:

>In article <411 at npois.UUCP> adam at npois.UUCP (Adam V. Reed) writes:
>>
>>According to K&R, Appendix A, section 9, the braces together with the
>>declarations and statements they enclose form a single syntactic entity
>>called "compound statement" or, equivalently, "block". This means that
>>the braces are conceptually associated with the statements they enclose,
>>and NOT with anything before or after. I use the form on the right
>>exclusively, because I find it easier to keep a "block" together in my
>>mind if it looks like, well, a single BLOCK. Except for people who have
>>assimilated some very sloppy mental habits, programs are easier to read
>>if visual entities correspond to syntactic and conceptual entities.
>
>   What!?  The compound statement to be or not to be executed depending on
>the value of an "if" expression has no conceptual association with that "if"
>clause???  Well I'll be damned!  I guess I'll just leave out all the if's, and
>while's, and repeat's, and for's in my programs.
>   Sloppy mental habits?  Harumph!

It is the ENTIRE compound statement, and NOT the braces delimiting it,
that is conceptually associated with the expression on which it depends.
This dependence is optimally communicated by indenting the ENTIRE dependent
statement relative to the expression on which it depends, e.g.

		if (condition)
			{
			declarations;

			statements;
			}

						Adam V. Reed (npois!adam)



More information about the Comp.lang.c mailing list