Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!haven!uflorida!novavax!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Braces are not Compiler-Fluff. Summary: Really? Message-ID: <292@twwells.uucp> Date: 5 Jan 89 13:47:00 GMT References: <272@twwells.uucp> <849@unh.UUCP> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 85 In article <849@unh.UUCP> jeff@unh.UUCP (Jeffrey E. F. Friedl) writes: : : In article <272@twwells.uucp> bill@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. : 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. Drop using analogies. They are never proper means of demonstration. Not only that, but yours does not even succeed as an illustration. It's completely wrong, there being no relationship between the purpose of page numbers in a book and the purpose of indentation or braces in a program. The page numbers are in the book because one wants absolute information, to be used without reference to the surrounding pages; the braces or indentation are there to indicate relationships. The two are not comparable. : > [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)? They are there for the *writer* of the code. They help prevent mistakes. Also, closing braces provide continuity in the indentation so that determining what the indentation actually is becomes an easier perceptual task. : It's just easier to see it right there (by : the page numbers, or the braces -- both of which augment what you're : already able to find determine). But you have forgotten or don't know an important fact: to understand the code, using braces, one must *conceptually* identify the relationship between the parts. This takes time. This also takes concentration and part of one's short term memory. Indentation, on the other hand, relies on one's perceptual systems; this is automatic, takes essentially no time, and costs nothing in terms of concentration and short term memory. : 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". But that is an incorrect point of view: before asking "how can I use..." one *must* ask "ought I use...". And in this case, the answer is clear: braces, given the existence of indentation, are the wrong solution and should not be used for that function. It is therefore purposeless to ask how they should be used for that function. To summarize: there are (at least) two possible ways to indicate control relationships in a program, indentation and braces. They are equivalent, in the sense that the braces can always be used to generate the proper indentation and the indentation can always be used to generate the proper braces. Thus, the choice between them is between which conveys the information most readily. Since indentation does so with little cost to the reader, but braces with a large cost, the choice is clear: use indentation to convey the information. Now, for understandability, braces have little use other than to convey this control information (the exception being that closing braces provide continuity of indentation, an argument for always using braces with multiple levels of indentation) this implies that braces should be used for their only essential function: telling the compiler what the control relationships are, and should otherwise be made as unobtrusive as possible. This, among style issues, is one of the few that is actually decidable on objective grounds. Arguing it, without reference to those objective grounds is pointless. --- Bill { uunet!proxftl | novavax } !twwells!bill