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

  1. Newsgroups: comp.software-eng
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!emory!nastar!phardie
  3. From: phardie@nastar.uucp (Pete Hardie)
  4. Subject: Re: C Code Layout
  5. Message-ID: <1992Dec18.160324.11869@nastar.uucp>
  6. Organization: Digital Transmission Systems, Duluth, GA.
  7. References: <1992Dec15.023235.17090@seq.uncwil.edu> <45360002@hpcuhe.cup.hp.com>
  8. Date: Fri, 18 Dec 1992 16:03:24 GMT
  9. Lines: 61
  10.  
  11. In article <45360002@hpcuhe.cup.hp.com> defaria@hpcuhe.cup.hp.com (Andy DeFaria) writes:
  12. >That's because you view it as an open ({) and corresponding close (}).
  13.  
  14. Accurate enough.
  15.  
  16. >To me,
  17. >such statements, while they require a close, should not require an open.
  18.  
  19. I disagree.  Symmetry is desirable in a language.  I detested PL/1 for its
  20. requiring a ';' at the end of *every* statement - it implied that the 
  21. statement "else i = 3;" was a valid standalone statement.
  22.  
  23. >In
  24. >other words the assumption should be that I always have a compound statement
  25. >and must tell the compiler when it's done.
  26.  
  27. Again, I disagree.  Since a compaund statement is lexically identical
  28. to a single statement, they should have the same form.
  29.  
  30. >C required that I also specify an
  31. >open but I see no reason to devote a full line to it!  I detest:
  32. >
  33. >    if (condition)
  34. >       statement;
  35. >   statement;
  36.  
  37. I don't quite understance why this bothers you.  
  38.  
  39. >or     
  40. >    if (condition) statement;
  41. >    statement;
  42. >
  43. >It's just too easy to misread the fact that C will only execute the first
  44. >statement if condition is true.
  45.  
  46. This I agree with - it's far too easy to miss the statement on the end of the 
  47. line and assume the second one is controlled by the condition.
  48.  
  49. >I would code:
  50. >
  51. >    if (condition) {
  52. >       statement;
  53. >    } /* if */
  54. >
  55. >    statement;
  56. >
  57. >Note I label my terminating close (}).  Now think about it.  When eyeballing
  58. >the above code and reading the if statement: Do you really care where it has
  59. >opened or when it has closed?  To me the open is inconsequential: Of course it
  60. >starts but where does it end?
  61.  
  62. I think that this is why I prefer the braces on separate lines - to make their
  63. associations clear.  I dislike a comment that is placed for syntactic reference.I prefer comments be reserved for semantic clarification.  In some of the
  64. code I've seen, there would be a forest of /* if */'s hiding the desired
  65. semantic information.
  66.  
  67. -- 
  68. Pete Hardie:  phardie@nastar  (voice) (404) 497-0101
  69. Digital Transmission Systems, Inc., Duluth GA
  70. Member, DTS Dart Team           |  cat * | egrep -v "signature virus|infection" 
  71. Position:  Goalie               |
  72.