home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / software / 5130 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  2.5 KB

  1. Xref: sparky comp.software-eng:5130 comp.lang.c:18803
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
  3. From: hartman@ulogic.UUCP (Richard M. Hartman)
  4. Newsgroups: comp.software-eng,comp.lang.c
  5. Subject: Re: C code Layout
  6. Message-ID: <771@ulogic.UUCP>
  7. Date: 22 Dec 92 23:12:15 GMT
  8. References: <1992Dec17.081451@eklektix.com> <AJ3U.92Dec17172600@onyx.cs.virginia.edu> <1992Dec18.151710.23851@scott.skidmore.edu>
  9. Followup-To: comp.lang.c
  10. Organization: negligable
  11. Lines: 95
  12.  
  13. In article <1992Dec18.151710.23851@scott.skidmore.edu> pvonk@scott.skidmore.edu (Pierre VonKaenel) writes:
  14. >In article <AJ3U.92Dec17172600@onyx.cs.virginia.edu> aj3u@onyx.cs.virginia.edu (Asim Jalis) writes:
  15. >>I prefer the K&R style of using braces with statement blocks:
  16. >>
  17. >>    keyword (condition) {
  18. >>        statement1;
  19. >>        statement2;
  20. >>        statement3;
  21. >>    }
  22. >>
  23. >
  24. >I used to use this syntax until once I forgot one of the { and it
  25. >wasn't noticable.  Took a while to find that bug.  At least..
  26. >
  27. >    keyword (condition) 
  28. >    {
  29. >        statement1;
  30. >        statement2;
  31. >        statement3;
  32. >    }
  33. >
  34. >is easier to spot.  It's also more symmetric, which means from an
  35. >artistic view, more pleasing   (I know, I know... subjective!)
  36.  
  37.  
  38. All this argument between style A:
  39.  
  40.     keyword (condition) {
  41.         statement1;
  42.         statement2;
  43.         statement3;
  44.     }
  45.  
  46. and style B:
  47.  
  48.     keyword (condition) 
  49.     {
  50.         statement1;
  51.         statement2;
  52.         statement3;
  53.     }
  54.  
  55.  
  56. ... am I in the minority here by preferring style C:
  57.  
  58.     keyword (condition) 
  59.         {
  60.         statement1;
  61.         statement2;
  62.         statement3;
  63.         }
  64.  
  65. This is essentially a minor variant with all the advantages
  66. of style B, but the additional advantage that the braces match
  67. the indentation level of the statements they surround, consider
  68. this -- if you have:
  69.  
  70.  
  71.     if (cond)
  72.         statement;
  73.  
  74. and then have to add another statement to it:
  75.  
  76.     if (cond)
  77.     {
  78.         statement;
  79.         statement2;
  80.     }
  81.  
  82. My editor (vi with auto-indent set) requires additional effort
  83. to move those braces back to the "outdented" position, whereas
  84.  
  85.     if (cond)
  86.         {
  87.         statement;
  88.         statement2;
  89.         }
  90.  
  91. can be accomplished much quicker.
  92.  
  93.  
  94. btw: I really detest the K&R style (style A), for reasons
  95. already mentioned, among them (but not limited to):
  96.  
  97.     difficult to see block alignment
  98.     hides "else" keyword
  99.     even MORE difficult to make a single-line if-body
  100.         into a block than style B
  101.  
  102.         -Richard Hartman
  103.         hartman@uLogic.COM
  104.  
  105. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  106. "Ideas are not responsible for the people who believe them."
  107.  
  108.