Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!wuarchive!udel!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Braces Message-ID: <15102@smoke.brl.mil> Date: 6 Feb 91 19:33:10 GMT References: <2293@inews.intel.com> <15090@smoke.brl.mil> <2324@inews.intel.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 41 In article <2324@inews.intel.com> bhoughto@pima.intel.com (Blair P. Houghton) writes: >... I'd like to know where it came from, not the reasons >or rationalizations for its use: those I'll get from the >source. You seem to be presuming that everybody else using aligned-brace style is mimicking a style originated by a single source. It is much more likely that several minds thinking about the subject have arrived at similar conclusions for similar reasons. In my case it originated as an experiment to see if I could find a code layout that made it easier for me to understand the code structure. I tried several variations in C coding style, allowing enough time to become familiar with each so that I could fairly judge how each worked in practice. (When editing existing code, if it follows a consistent style then I try to adhere to that style also; consistency is very important.) My use of whitespace near punctuators and operators has varied over the years, but at any given moment I use the style that seems to be the best compromise between patent structural visibility and the ability of other programmers to cope with it. One of the biggest problems with the K&R style while ( ... ) { ... } is that it leads many novice programmers to misunderstand the function of the braces; they start to think that they are part of the punctuation for the "while" statement, which is wrong. I have a similar objection to a form widely used by Bell Labs programmers: return(expression); which has caused many programmers to think that the parentheses are required, which is wrong. While these misconceptions may seem benign, I have seen a lot of time wasted in explaining to such misled programmers why while ( ... ) simple_statement; and return expression; are valid C code. Styles that reinforce a correct understanding of the language seem preferable to ones that mislead.