home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13203 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  4.5 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 na
  5. Message-ID: <rmartin.715445973@thor>
  6. Date: 2 Sep 92 14:59:33 GMT
  7. References: <714668024@thor> <6800007@tisdec.tis.tandy.com> <1992Aug26.130335.26725@hemlock.cray.com> <1992Aug26.194538.1598@spss.com> <rmartin.714931485@thor> <1992Sep1.192043.16224@mksol.dseg.ti.com>
  8. Sender: news@Rational.COM
  9. Lines: 81
  10.  
  11. mccall@mksol.dseg.ti.com (fred j mccall 575-3539) writes:
  12.  
  13. |In <rmartin.714931485@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  14.  
  15. |>So we have rules.  These rules protect us average types from the guys
  16. |>who think they are "real good drivers".  When some guy blows a stop
  17. |>sign, it doesn't matter to me, one whit, if he is the greatest driver
  18. |>in the world, I will still applaud the cop who pulls him over.
  19.  
  20. |But the problem is that, all too often, we lose sight of what we
  21. |wanted the rule to do for us and the means BECOMES the goal.  I've
  22. |seen this more times than I care to mention when it comes to 'rules'
  23. |and their 'enforcement'.
  24.  
  25. And sometimes this is bad, and sometimes this is good.  One of the
  26. reasons for having rules is to limit the number of variables under
  27. consideration.  Programming is hard, any convention that can help us
  28. narrow our focus on the solution could be an advantage.  If the
  29. convention is shown to be usable in all cases, and advantageous in
  30. nearly all, then its adoption as a rule which is never violated gives
  31. us one less thing to think about.
  32.  
  33. |The real rule on 'goto' ought to be something like, "Presence of a
  34. |goto in code MAY indicate poorly structured and/or overly complex
  35. |code.  Any use of a goto should be carefully examined to determine if
  36. |there are not better alternative structures which will be more easily
  37. |understood and maintained by others.  If, and only if, this is the
  38. |case, use a 'goto'."  Clearly document the purpose and effect of the
  39. |jump at both the 'goto' and 'label'.  Avoid jumps from different
  40. |places to the same label.  Similar rules for various other
  41. |'questionable' or 'abused' constructs.
  42.  
  43. This is far too weak.  It is tantamount to saying: "use goto when you
  44. feel like it, but be ready to justify it if questioned."  to quote
  45. Jack D. Ripper: "I am going to have to answer for what I have done;
  46. and I think I can."
  47.  
  48. I think the requirement should read as follows:  "Presence of a goto
  49. indicates a flaw in program structure as defined in the tenets of
  50. Structured Programming.  Goto statements should only be used when
  51. physically necessary to conform to project requirements.  For example,
  52. to increase the throughput of a critical inner loop."
  53.  
  54. IMHO, there simply isn't any other reason to consider using a goto.
  55.  
  56. |The argument, "Well, you never NEED to use a goto." is hardly a
  57. |justification for not using them, either.  You can also write
  58. |everything in the world (wrt 'structure') with only a conditional test
  59. |and a jump.  That's hardly a good reason to say that you SHOULD.
  60.  
  61. You miss the point.  Structured programming is the construction of
  62. algorithms based on 3 control structures {sequence, selection and
  63. repetition} concatenated toghether in a composition hierarchy.  This
  64. hierarchy is the "structure" that structured programming talks about.
  65. It is regular, and it is recursively defined.  And any algorithm can
  66. be made to conform to such a structure.
  67.  
  68. Conforming algorithms are aggregate of code fragements which are
  69. entered at the top and exit at the bottom.  Each such fragment has a
  70. purpose which is independent of all but the fragment immediately
  71. above, and the fragment immediately below it.  Thus, the clients and
  72. suppliers of the fragment are known and limited.  This makes the
  73. fragments easy to understand and easy to maintain.  The dependencies
  74. between the fragments are regular, and limited, so that changes in one
  75. fragment have a minimum effect on the others.
  76.  
  77. Now, you never need to violate this structure (except when physical
  78. contraints of throughput or space are extremenly critical).  So why
  79. would you violate it?  What justification is there?  Is it ok to
  80. weaken the structure of a code, introduce foreign dependencies between
  81. modules, and make the code harder to maintain, just because you think
  82. you can write it a bit faster if you don't have to think about it's
  83. structure?
  84.  
  85.  
  86.  
  87. --
  88. Robert Martin                        Training courses offered in:
  89. R. C. M. Consulting                       Object Oriented Analysis
  90. 2080 Cranbrook Rd.                        Object Oriented Design
  91. Green Oaks, Il 60048 (708) 918-1004       C++
  92.