home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / msdos / programm / 12023 < prev    next >
Encoding:
Text File  |  1993-01-12  |  5.9 KB  |  155 lines

  1. Xref: sparky comp.os.msdos.programmer:12023 comp.lang.c++:19027 comp.lang.c:19592
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
  3. From: hartman@ulogic.UUCP (Richard M. Hartman)
  4. Newsgroups: comp.os.msdos.programmer,comp.lang.c++,comp.lang.c
  5. Subject: Re: Newbie Wants Advice on C-Programming
  6. Message-ID: <853@ulogic.UUCP>
  7. Date: 12 Jan 93 17:05:24 GMT
  8. References: <1992Dec31.043002.24014@ucc.su.OZ.AU> <FISCHER.93Jan9030817@orange.iesd.auc.dk> <1993Jan11.131838.12844@cbnewsj.cb.att.com>
  9. Followup-To: comp.os.msdos.programmer
  10. Organization: negligable
  11. Lines: 142
  12.  
  13. In article <1993Jan11.131838.12844@cbnewsj.cb.att.com> davet@cbnewsj.cb.att.com (Dave Tutelman) writes:
  14. >In article <FISCHER.93Jan9030817@orange.iesd.auc.dk> fischer@iesd.auc.dk (Lars Peter Fischer) writes:
  15. >>
  16. >>>>>>> "Michael" == Michael Malak (malak@grebyn.com)
  17. >>>>>>> "Lars" == fischer@iesd.auc.dk (Lars Peter Fischer)
  18. >>>>>>> "John" == John MAX Skaller (maxtal@extro.ucc.su.OZ.AU)
  19. >>
  20. >>John>     Seems to me that the simple concept of
  21. >>John> nesting the symbol table so that symbols go out of scope at the
  22. >>John> end of the block is very nice.
  23. >
  24. >C and C++ have this, too.
  25. >
  26. >My organization's coding standard (adopted explicitly to make our software
  27. >easier to read and maintain) calls for declaring and initializing
  28. >variables as close as possible to their point of first use.  In the ability
  29. >to meet this goal:
  30. >    C++ good.
  31. >    Pascal bad.
  32.  
  33. I am a C person and I have to disagree with your standard.  In C++
  34. (and, I think, ANSI C although I am not certain) it is possible to
  35. declare new variables almost anywhere.  e.g.:
  36.  
  37.     main()
  38.     {
  39.     cout << "stuff" << endl;
  40.     int i = 2;
  41.     cout << "i is " << i << endl;
  42.     }
  43.  
  44. This, you would agree, is declaring as close to the usage as possible,
  45. but let's say the function is a little longer than that.  I want to
  46. add a loop w/ the control variable "i".  Where can I check to see if
  47. it has already been declared or not if all the variable declarations
  48. are scattered throughout the code?
  49.  
  50. The biggest concession I will make to this practice is declaring 
  51. variables at the top of the nearest enclosing block.  Which I
  52. don't think Pascal can do anyway, aren't they limited to the 
  53. enclosing function/procedure?
  54.  
  55. >As someone who has a few years real-world programming experience with
  56. >each of C and Pascal, the ONLY times I've ever wished for nested
  57. >procedures in C involved a combination of:
  58. > - Repetitive operations of the same pattern within a single function,
  59. >   that weren't repeated in any other function.
  60.  
  61. static function.
  62.  
  63. > - A lot of function-specific state information (i.e.- local variables)
  64. >   required for this operation... too many to make each one an argument
  65. >   of a procedure.
  66.  
  67. struct.
  68.  
  69. >In such cases, I use macros in C; not as elegant as nested procedures,
  70. >but they do the job.
  71.  
  72. that works too.  (actually I use macros more than static functions, 
  73. but then I don't always care about poluting the name space as much
  74. as I should...)
  75.  
  76.  
  77.  
  78. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  79. Blasting, bursting, billowing forth with    |
  80. the power of ten billion butterfly sneezes,    |    -Richard Hartman    
  81. Man, with his flaming fire,            |    hartman@uLogic.COM
  82. has conquered the wayword breezes.        |
  83. ----- News saved at 12 Jan 93 17:04:17 GMT
  84. In article <1993Jan11.131838.12844@cbnewsj.cb.att.com> davet@cbnewsj.cb.att.com (Dave Tutelman) writes:
  85. >In article <FISCHER.93Jan9030817@orange.iesd.auc.dk> fischer@iesd.auc.dk (Lars Peter Fischer) writes:
  86. >>
  87. >>>>>>> "Michael" == Michael Malak (malak@grebyn.com)
  88. >>>>>>> "Lars" == fischer@iesd.auc.dk (Lars Peter Fischer)
  89. >>>>>>> "John" == John MAX Skaller (maxtal@extro.ucc.su.OZ.AU)
  90. >>
  91. >>John>     Seems to me that the simple concept of
  92. >>John> nesting the symbol table so that symbols go out of scope at the
  93. >>John> end of the block is very nice.
  94. >
  95. >C and C++ have this, too.
  96. >
  97. >My organization's coding standard (adopted explicitly to make our software
  98. >easier to read and maintain) calls for declaring and initializing
  99. >variables as close as possible to their point of first use.  In the ability
  100. >to meet this goal:
  101. >    C++ good.
  102. >    Pascal bad.
  103.  
  104. I am a C person and I have to disagree with your standard.  In C++
  105. (and, I think, ANSI C although I am not certain) it is possible to
  106. declare new variables almost anywhere.  e.g.:
  107.  
  108.     main()
  109.     {
  110.     cout << "stuff" << endl;
  111.     int i = 2;
  112.     cout << "i is " << i << endl;
  113.     }
  114.  
  115. This, you would agree, is declaring as close to the usage as possible,
  116. but let's say the function is a little longer than that.  I want to
  117. add a loop w/ the control variable "i".  Where can I check to see if
  118. it has already been declared or not if all the variable declarations
  119. are scattered throughout the code?
  120.  
  121. The biggest concession I will make to this practice is declaring 
  122. variables at the top of the nearest enclosing block.  Which I
  123. don't think Pascal can do anyway, aren't they limited to the 
  124. enclosing function/procedure?
  125.  
  126. >As someone who has a few years real-world programming experience with
  127. >each of C and Pascal, the ONLY times I've ever wished for nested
  128. >procedures in C involved a combination of:
  129. > - Repetitive operations of the same pattern within a single function,
  130. >   that weren't repeated in any other function.
  131.  
  132. static function.
  133.  
  134. > - A lot of function-specific state information (i.e.- local variables)
  135. >   required for this operation... too many to make each one an argument
  136. >   of a procedure.
  137.  
  138. struct.
  139.  
  140. >In such cases, I use macros in C; not as elegant as nested procedures,
  141. >but they do the job.
  142.  
  143. that works too.  (actually I use macros more than static functions, 
  144. but then I don't always care about poluting the name space as much
  145. as I should...)
  146.  
  147.  
  148.  
  149. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  150. Blasting, bursting, billowing forth with    |
  151. the power of ten billion butterfly sneezes,    |    -Richard Hartman    
  152. Man, with his flaming fire,            |    hartman@uLogic.COM
  153. has conquered the wayword breezes.        |
  154.  
  155.