home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13301 < prev    next >
Encoding:
Internet Message Format  |  1992-09-04  |  3.1 KB

  1. Path: sparky!uunet!UB.com!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: GOTO, was: Tiny proposal for named loops.
  5. Message-ID: <rmartin.715618743@thor>
  6. Date: 4 Sep 92 14:59:03 GMT
  7. References: <2318@devnull.mpd.tandem.com> <rmartin.715001372@thor> <4192@papaya.bbn.com> <1992Sep2.131733.20676@terminator.cc.umich.edu> <r <KERS.92Sep4082931@cdollin.hpl.hp.com>
  8. Sender: news@Rational.COM
  9. Lines: 64
  10.  
  11. kers@hplb.hpl.hp.com (Chris Dollin) writes:
  12.  
  13. |In article ... rmartin@thor.Rational.COM (Bob Martin) writes:
  14.  
  15. |   You don't have to make up your own rules.  Some other guys, who have
  16. |   thought about it alot, have put together a pretty well thought through
  17. |   set of rules.  Moreover, the industry has, for the most part, accepted
  18. |   those rules as valid.  Moreover, it has been proven that those rules
  19. |   are always workable, and it has been shown that they help to make code
  20. |   more readable and maintainable.  
  21.  
  22. |In what sense do you claim that ``these rules'' (by which I understand you to
  23. |mean the usual rules of structured programming) have been ``proven'' to be
  24. |``workable''? 
  25.  
  26. Only that it has been proven that gotos are unecessary.  That any
  27. algorithm can be written in terms of sequence, selection and
  28. repetition.
  29.  
  30. |It's certainly true that any procedure can be rewritten in structured style
  31. |(ie, using only while, if, and sequencing as control structures). But the
  32. |easiest proof of this -- turn it into a loop wrapped round a case (chained ifs,
  33. |if you want to be picky) -- also shows that it's not necessarily a good idea,
  34. |if what you want is *clear* code.
  35.  
  36. |And clearness is as much a matter of psychology as of mathematics. 
  37.  
  38. Yes, so lets forget the psychological part and focus on the
  39. mathematical part.  Constructiong your algorithms based on SP causes
  40. you to separate paths that you might otherwise combine (with gotos).
  41. This separation decouples the paths from each other, so that changes
  42. made in one path do not affect the other paths.
  43.  
  44. We don't use SP because it makes the code "prettier" or
  45. psychologically more gratifying.  We use it because it separates the
  46. code fragments and reduces coupling.  This makes the code easier to
  47. maintain.
  48.  
  49. |There's a
  50. |lot of empirical evidence to suggest that traditional SP ``works'', ie, that 
  51. |for very many programming problems, they are an effective solution. [The
  52. |evidence is the large number of programs written effectively in that style.]
  53. |But there's also evidence that they're not *enough* -- that other control
  54. |structures are needed for clarity -- consider
  55.  
  56. |    * procedures
  57. |    * FOR-loops (of various kinds)
  58. |    * N+1/2 times loops
  59. |    * Scheme-style use of tail-call
  60. |    * Co-routines
  61. |    * Higher-order functions
  62.  
  63. |for example.
  64.  
  65. Agreed.
  66. The last thing I advocate is a reduction of all code to one linear
  67. stream of sequence, selection and repetition.  
  68.  
  69.  
  70. --
  71. Robert Martin                        Training courses offered in:
  72. R. C. M. Consulting                       Object Oriented Analysis
  73. 2080 Cranbrook Rd.                        Object Oriented Design
  74. Green Oaks, Il 60048 (708) 918-1004       C++
  75.