home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / software / 5029 < prev    next >
Encoding:
Text File  |  1992-12-17  |  2.2 KB  |  56 lines

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