home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18961 < prev    next >
Encoding:
Text File  |  1992-12-29  |  5.3 KB  |  120 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mole-end!mat
  3. From: mat@mole-end.matawan.nj.us
  4. Subject: Re: Pascal as road to C (was Re: Newbie Wants Advice on C-Programming)
  5. Message-ID: <1992Dec28.151237.4358@mole-end.matawan.nj.us>
  6. Summary: There are things worse than none at all ...
  7. Organization: :
  8. References: <1992Dec24.172333.7339@grebyn.com> <1992Dec25.070024.15672@grebyn.com> <1992Dec28.045707.11191@grebyn.com>
  9. Date: Mon, 28 Dec 1992 15:12:37 GMT
  10. Lines: 108
  11.  
  12. (I've put the history at the _end_ where it's out of the way.)
  13.  
  14. > >> Pascal has the following advantages over C:
  15. > >>    1) It has structured syntactic blocks for constants, types and
  16. > >>       variables.
  17.  
  18. > >...  Would you require a cook to measure out all the ingredients specified
  19. > >by tablespoons before measuring any ingredient specified by cups?
  20.  
  21. > No, but I would require the cook to do the following in order:
  22. >     1) Purchase the ingredients
  23. >     2) Prepare the courses
  24. >     3) Serve the meal
  25.  
  26. And I think one should design the program, then write the program, then
  27. compile the program, then run the program!
  28.  
  29. Would you put whipped cream on the berries for dessert before you serve
  30. the appetizers?  Or dress a salad before the beef when you will serve it
  31. after (its proper place, BTW)?  Or flame the dessert before ladling out
  32. the soup?
  33.  
  34. > ...  you're arguing that it's better to clump related definitions
  35. > together, even though some may be constants and others types or
  36. > variables, such as:
  37.  
  38. > #define BUFFER_SIZE 10000
  39. > char buffer[ BUFFER_SIZE ];
  40.  
  41. > I.e., do not have "constant blocks" and "variable blocks".  There are
  42. > strong arguments for both ways, _but_ the Pascal organization is better
  43. > than none at all.
  44.  
  45. And a dictionary is better for finding words, but an encyclopedia better
  46. for finding knowledge: if the only structure you can find yourself is the
  47. individual declaration, then the Pascal order has an argument, but if you
  48. have a larger structure to your work (and in C you should; in C++ you'd
  49. better) then the Pascal order discards information.  If you are constrained
  50. to it, you'll never learn to raise the level at which you program.
  51.  
  52. > >The classical Pascal expression of a loop-and-a-half cannot be written
  53. > >as a while() because Pascal's expression syntax is too weak.  ...
  54. > >What results is a circumlocution ... more ... control flow and temporary
  55. > >variable managing than ... problem; This is a very bad form of incohesion:
  56.  
  57. > >    if not X
  58. > >        manage the loop
  59. > >    else
  60. > >        solve the problem
  61.  
  62. > Actually, it's a good use of nested procedures.  In C, we have:
  63. > while ( TRUE )  {
  64.  
  65. Actually, it's not.  Typically, the idiomatic C is one half to one
  66. tenth the length of the Pascal style, and more direct, to boot.  Quoting
  67. Kernighan and Plauger, ``How can code that is an order of magnitude too
  68. large be considered reliable?''  And again, ``Jumping around has proved
  69. to be a fruitful source of errors.''  Whether it's done by goto's or
  70. by circumlocutions of a language whose hobbled statement syntax prevents
  71. you from dealing with its stillborn expression syntax, you are still
  72. forced to connect disparate units of code and verify yourself that
  73. they are activated together correctly under the correct circumstances.
  74.  
  75. That is _not_ structured programming.  Dijkstra to the contrary, there
  76. are only two fundamental constructs in structured programming: Governs
  77. and Invokes.  Governs relates a block of code to the single condition
  78. that activates it as a unit; Invokes relates a block of code to the
  79. remote request that activates it as a unit.  These allow you to trace
  80. efficient causes forward and final causes back; the ability to trace
  81. both kinds of cause is the essence of understanding a program.
  82.  
  83. Deliberately scattering the statements activated under a single
  84. circumstance across several levels of control structure does not
  85. structure a program; it scrambles it.
  86.  
  87. > ...  "break" and "continue", as well as mid-function "return"s are nothing
  88. > more than "goto"s in disguise.
  89.  
  90. Many problems structure themselves quite nicely as a linear set of
  91. cases; many tests will not structure themselves well in any other way.
  92. Like it or not, the loop-and-a-half exists in well-formulated problems.
  93. And the best thing to do with a case that has been handled is to throw
  94. it away (return) and get on to the next case.
  95.  
  96. > ...  It's a prime example of how C gives beginners enough rope to hang
  97. > themselves.  Someone who's suffered through the strictness of Pascal
  98. > can appreciate exactly when to use "break"s, "continue"s, "goto"s, and
  99. > mid-function "return"s.
  100.  
  101. Negative training is bad for dogs and bad for people.
  102.  
  103. The proper training is not fettering and scourging by Pascal but the
  104. discipline of annotating code with provable assumptions and assertions.
  105.  
  106.  
  107. (Here follows a sad and weary history ...)
  108.  
  109. In article <1992Dec28.045707.11191@grebyn.com>, malak@grebyn.com (Michael Malak) writes:
  110. > In article <1992Dec27.031157.27179@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
  111. > >In article <1992Dec25.070024.15672@grebyn.com>, malak@grebyn.com (Michael Malak) writes:
  112. > >> In article <1hdpluINN1lv@agate.berkeley.edu> faustus@ygdrasil.CS.Berkeley.EDU (Wayne A. Christopher) writes:
  113. > >> >In article <1992Dec24.172333.7339@grebyn.com> malak@grebyn.com (Michael Malak) writes:
  114. -- 
  115.  (This man's opinions are his own.)
  116.  From mole-end                Mark Terribile
  117.  
  118.  mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
  119.