home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.arch:10419 comp.lang.misc:3500
- Newsgroups: comp.arch,comp.lang.misc
- 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
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: A challenge to the anti-goto
- Message-ID: <1992Nov5.181511.12594@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1css0nINNc51@agate.berkeley.edu> <Bwznzx.Dr1@mentor.cc.purdue.edu> <Bx0BuG.s4@mentor.cc.purdue.edu> <1992Nov5.111943.21554@harlqn.co.uk>
- Date: Thu, 5 Nov 1992 18:15:11 GMT
- Lines: 43
-
- In article <1992Nov5.111943.21554@harlqn.co.uk>, daveb@harlqn.co.uk (Dave Berry) writes:
- |> It's easy to get rid of these gotos. Every goto can be replaced by a
- |> tail-recursive function call. This can be compiled into the same machine
- |> code. Here is Herman's example, gratuitously rewritten in ML.
-
- I posted this a couple of weeks ago, but my newshost daemon blocked
- my outgoing mail at that time.
-
- "Structured Programming With GOYTO Statements", D.E. Knuth, Current
- Trends in Programming Methodology, R.T. Yeh Ed., Prentice-Hall, Inc.,
- 1977:
-
- [...] Rule number one for simplifying procedure calls is:
-
- If the last action of procedure p before it returns is
- to call procedure q, simply GOTO the beginning of procedure
- q instead.
-
- (We must forget for the time being that we don't like GOTO
- statements.) It is easy to confirm the validity of this rule,
- [...]
- Incidentally, the converse of the above rule is also true (see
- [Knuth and Floyd, "Notes on Avoiding GOTO Statements", Computer
- Science Technical Report CS148, Stanford University (1979)]):
- GOTO statements can always be eliminated by declaring suitable
- procedures, each of which calls another as its last action.
- This shows that procedure calls include GOTO statements as
- a special case; it cannot be argued that procedures are
- conceptually simpler than GOTO's, although some people have
- made such a claim.
-
- In short, a procedure call is *at least* as messy, non-local, and
- spaghetti prone as GOTOs. In common practice, GOTOs are presently
- *easier* for the compiler to analyze and optimize than interprocedural
- calls are. To be sure, the code which is done as procedure calls
- *can* be compiled to the same code by a *very* clever compiler
- (and assuming that the language doesn't require that separate
- compilation work). Last, but not least, is the fact that *sometimes*
- a GOTO is actually easier to read and maintain (though I'm still
- not sure this is the case with Herman Rubin's program).
-
- --
- J. Giles
-