home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.software-eng
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!ncar!csn!raven!rcd
- From: rcd@raven.eklektix.com (Dick Dunn)
- Subject: Re: C code Layout
- Message-ID: <1992Dec17.074616@eklektix.com>
- Organization: eklektix - Boulder, Colorado
- References: <1992Dec14.175533.8400@fcom.cc.utah.edu> <1992Dec15.073140@eklektix.com> <1992Dec15.153859.29057@nastar.uucp>
- Date: Thu, 17 Dec 1992 07:46:16 GMT
- Lines: 45
-
- phardie@nastar.uucp (Pete Hardie) writes:
- [I mentioned the "One True Brace Style" (K&R)]
- >A brief comment (NPI :->) here. I find that the brace style:
- > if(condition)
- > {
- > statement;
- > ...
- > }
- >is more readable than this style:
- > if(condition) {
- > statement;
- > ...
- > }
- >for one main reason - the alignment of the open and close braces is the same,
- >and this (to me) ties the block of code together. IMHO, this outweighs the
- >additional single line per block of vertical space.
-
- This is a real opinion thing. I've written in lots of languages, including
- a lot of C for a lot of years, and I've worked with people with similarly
- extensive experience...we sit down and compare notes on style nits, and
- this is one point where I *can't* predict how people's opinions will fall!
- We can write to such similar styles that we might not be able to tell which
- code is whose except for the position of the opening brace. I think, over
- the folks like this that I've met, it comes down ever-so-slightly in favor
- of K&R over vertical alignment, but not by enough to call it a win.
-
- I wish we had a way to get some useful objective data on this. My hand-
- wave against the argument Pete presents is that the K&R style has one line
- at either end of the bracketed range, rather than two at the start and one
- at the end. Anyway, humans don't pay much attention to the brackets! We
- use indentation. Don't believe it? Just try people on something like:
- if (i <= 0)
- mumble = 0;
- return;
- In general, if indentation fails to match the real nesting, people will
- "see" the nesting (wrongly) implied by indentation. Also, if you give { a
- line by itself, you get the rather stringy
- }
- else
- {
- instead of
- } else {
- --
- Dick Dunn rcd@eklektix.com -or- raven!rcd Boulder, Colorado USA
- ...Mr. Natural says, "Use the right tool for the job."
-