home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13541 < prev    next >
Encoding:
Text File  |  1992-09-11  |  3.7 KB  |  75 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
  3. From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
  4. Subject: Re: GOTO, was: Tiny proposal for na
  5. Message-ID: <1992Sep11.183600.14889@mksol.dseg.ti.com>
  6. Organization: Texas Instruments Inc
  7. References: <2318@devnull.mpd.tandem.com> <rmartin.715001372@thor> <4192@papaya.bbn.com> <1992Sep2.131733.20676@terminator.cc.umich.edu> <rmartin.715526582@thor> <1992Sep9.205014.24925@mksol.dseg.ti.com> <rmartin.716168766@thor>
  8. Date: Fri, 11 Sep 1992 18:36:00 GMT
  9. Lines: 64
  10.  
  11. In <rmartin.716168766@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  12.  
  13. >mccall@mksol.dseg.ti.com (fred j mccall 575-3539) writes:
  14.  
  15. >|There are also places where the rules of Structured Programming do not
  16. >|create the most READABLE or MAINTAINABLE code, either.  In these
  17. >|cases, as well, they should be jettisoned.  This is the problem with
  18. >|having a set of 'usual rules'.  Meeting the rules becomes more
  19. >|important to some people than meeting the goals that the rules are
  20. >|supposed to be helping you with.
  21.  
  22. >Readability is subjective.  I find code without gotos more readable
  23. >than code with gotos.  Others, like you perhaps, find gotos to be more
  24. >readable in certain circumstances.  Life would be boring if we were
  25. >all the same.
  26.  
  27. If readability is subjective, why is that usually one of the reasons
  28. that Structured Programming Bigots (tm) always raise when lecturing
  29. about why we should all use The One True Style (tm).
  30.  
  31. >However, maintainability is much less subjective.  Gotos create
  32. >dependencies between blocks which complicate their flow patterns.
  33. >This makes them intriniscally more difficult to maintain.  Gotos also
  34. >tend to be used to merge many different control flows into one.  This
  35. >is also difficult to maintain since, as time wears on, exceptions
  36. >accumulate in the merged flows.
  37.  
  38. Nonsense.  If you had included some conditionals in there (e.g. "Gotos
  39. CAN create dependencies ...") I might agree with you.  As is, this is
  40. merely pedantic inflexibility.
  41.  
  42. Case in point.  Suppose you have a function which, during the course
  43. of it's processing, has a dozen possible error points.  If it checks
  44. status and finds an error at any point, the recovery required is the
  45. same.  If it finds an error at any point, it must not continue to try
  46. to process.  Using your method, one winds up with a dozen flags and
  47. code indented halfway across the page.  Trying to string together what
  48. the total algorithm looks like becomes problematic because of all the
  49. indentation breaks, flags, conditional statements strung from here to
  50. there, etc.  
  51.  
  52. Now lets examine the same situation using my method.  If the recovery
  53. can most reasonably be done by the calling function, I would simply
  54. use multiple exit points and exit the function with an error code at
  55. the first check that failed.  If the error recovery needed a lot of
  56. state information from variables in the function, I would use 'goto'
  57. when an error is found and put the error recovery off by itself (and
  58. would still have 2 returns from the single function).
  59.  
  60. The only way I see to clean up your approach is to create a function
  61. which does nothing but the error recovery and then pass it however
  62. many dozen parameters it needs so it can know enough about the state
  63. of the calling function.  Even then, you still have all that
  64. indentation running all the way across the bloody page.
  65.  
  66. [I don't know about you, but none of my compilers implement exceptions
  67. yet.] 
  68.  
  69.  
  70. -- 
  71. "Insisting on perfect safety is for people who don't have the balls to live
  72.  in the real world."   -- Mary Shafer, NASA Ames Dryden
  73. ------------------------------------------------------------------------------
  74. Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
  75.