home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / arch / 10419 < prev    next >
Encoding:
Internet Message Format  |  1992-11-14  |  2.6 KB

  1. Xref: sparky comp.arch:10419 comp.lang.misc:3500
  2. Newsgroups: comp.arch,comp.lang.misc
  3. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!hamblin.math.byu.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  4. From: jlg@cochiti.lanl.gov (J. Giles)
  5. Subject: Re: A challenge to the anti-goto
  6. Message-ID: <1992Nov5.181511.12594@newshost.lanl.gov>
  7. Sender: news@newshost.lanl.gov
  8. Organization: Los Alamos National Laboratory
  9. References: <1css0nINNc51@agate.berkeley.edu> <Bwznzx.Dr1@mentor.cc.purdue.edu> <Bx0BuG.s4@mentor.cc.purdue.edu> <1992Nov5.111943.21554@harlqn.co.uk>
  10. Date: Thu, 5 Nov 1992 18:15:11 GMT
  11. Lines: 43
  12.  
  13. In article <1992Nov5.111943.21554@harlqn.co.uk>, daveb@harlqn.co.uk (Dave Berry) writes:
  14. |> It's easy to get rid of these gotos.  Every goto can be replaced by a
  15. |> tail-recursive function call.  This can be compiled into the same machine
  16. |> code.  Here is Herman's example, gratuitously rewritten in ML.
  17.  
  18. I posted this a couple of weeks ago, but my newshost daemon blocked
  19. my outgoing mail at that time.
  20.  
  21. "Structured Programming With GOYTO Statements", D.E. Knuth, Current
  22. Trends in Programming Methodology, R.T. Yeh Ed., Prentice-Hall, Inc.,
  23. 1977:
  24.  
  25.    [...] Rule number one for simplifying procedure calls is:
  26.  
  27.       If the last action of procedure p before it returns is
  28.       to call procedure q, simply GOTO the beginning of procedure 
  29.       q instead.
  30.  
  31.    (We must forget for the time being that we don't like GOTO
  32.    statements.)  It is easy to confirm the validity of this rule,
  33.    [...]
  34.    Incidentally, the converse of the above rule is also true (see
  35.    [Knuth and Floyd, "Notes on Avoiding GOTO Statements", Computer
  36.    Science Technical Report CS148, Stanford University (1979)]):
  37.    GOTO statements can always be eliminated by declaring suitable
  38.    procedures, each of which calls another as its last action.
  39.    This shows that procedure calls include GOTO statements as
  40.    a special case; it cannot be argued that procedures are
  41.    conceptually simpler than GOTO's, although some people have
  42.    made such a claim.
  43.  
  44. In short, a procedure call is *at least* as messy, non-local, and
  45. spaghetti prone as GOTOs.  In common practice, GOTOs are presently
  46. *easier* for the compiler to analyze and optimize than interprocedural
  47. calls are.  To be sure, the code which is done as procedure calls
  48. *can* be compiled to the same code by a *very* clever compiler
  49. (and assuming that the language doesn't require that separate
  50. compilation work).  Last, but not least, is the fact that *sometimes*
  51. a GOTO is actually easier to read and maintain (though I'm still
  52. not sure this is the case with Herman Rubin's program).
  53.  
  54. -- 
  55. J. Giles
  56.