Braces are not Compiler-Fluff.

David Dyer-Bennet ddb at ns.UUCP
Fri Dec 30 03:42:29 AEST 1988


In article <849 at unh.UUCP> jeff at unh.UUCP (Jeffrey E. F. Friedl) writes [edited]:
:
:In article <272 at twwells.uucp> bill at twwells.uucp (T. William Wells) writes:
:>  I believe ...
:>  that braces exist only to make the compiler happy and should
:>  therefore be as unobtrusive as possible. 
:
:    Several people have said this and I disagree. 
:
:    It's been said that "indentation is enough to show the
:block structure". Sure, but taking this idea to an extreme,
:one could say that having all the pages in a book is sufficient
:to determine what page you're on -- one doesn't need page numbers.

I think you've got this analogy backwards -- indenting is like page numbers,
in that it enables you to determine "where you are" from looking at just the
current page / line.  Braces are like counting the pages in the book, because
you have to go all the way forwards or backwards to determine where you are.

:>  [braces glued to a control structure are] sometimes necessary for
:>  the compiler (but I always use the braces), but contributing little or
:		 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^      ^^^^^^^^^^^^^^^^^^^^^^^^^
:>  nothing to the understandability of the program.  The indentation of
:  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:>  the program is what tells you the control relationships; the braces
:>  are redundant information, at best they can augment what the
:>  indentation is already telling you.
:
:    If they contribute little or nothing, why put them when you don't
:need them (as you also said you do)?  

I can't speak for Mr. Wells, but I'd say one might always use braces to 
avoid forgetting to add them when going from a simple statement to a
compound statement under control of some construct.  That is, not for
readability per se but to avoid errors.  Because, after all, the braces
AREN'T redundant to the compiler.  The conflict here is that the compiler
reads the braces more easily (currently they don't read the indent at all),
whereas most humans I've asked read the indent more easily.

:    The only reason I say any of this is that if style is going
:to be discussed in a rational fashion (i.e. not a Religious FlameFest)
:then I think it's better to discuss braces from the point of view of
:"how can I use these braces to make things more readable" rather than
:from the point of view of "where can I stash these things".

I think the most readable use of braces is to make them inconspicuous,
except for the one case of the closing brace of a block when that's the
last character of a block.  The non-K&R styles I've seen have the braces
getting in the way of scanning the indent levels, for me.  

Yours for flame-free and informative discussions,
-- 
	-- David Dyer-Bennet
	...!{rutgers!dayton | amdahl!ems | uunet!rosevax}!umn-cs!ns!ddb
	ddb at Lynx.MN.Org, ...{amdahl,hpda}!bungia!viper!ddb
	Fidonet 1:282/341.0, (612) 721-8967 hst/2400/1200/300



More information about the Comp.lang.c mailing list