Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!crdgw1!steinmetz!algol!welty From: welty@algol.steinmetz (richard welty) Newsgroups: misc.misc,comp.misc Subject: Re: The "evil" GOTO (Was: 25 Years of BASIC) Summary: musings on a tired old subject Keywords: flogging, horses, dead Message-ID: <13775@steinmetz.ge.com> Date: 8 May 89 22:58:50 GMT References: <1791@ubu.warwick.UUCP> <1436@onion.reading.ac.uk> <1814@ubu.warwick.UUCP> <11136@bloom-beacon.MIT.EDU> <24047@agate.BERKELEY.EDU> <1384@cygnet.CYGNETSYSTEMS> <1166@mcrware.UUCP> Sender: news@steinmetz.ge.com Reply-To: welty@algol.steinmetz.ge.com (richard welty) Organization: New York State Institute for Sebastian Cabot Studies Lines: 103 Xref: utzoo misc.misc:6029 comp.misc:6005 the above set of keywords (who supplied these, anyway?) exactly sums up my own feelings on this topic ... In article <1166@mcrware.UUCP> jejones@mcrware.UUCP (James Jones) writes: >Let's all go read or reread Knuth, "Structured programming with goto >statements" (*Computing Surveys*, December 1974), so we can stop flogging >this dead horse, OK? It hasn't *quite* been 25 years since Dijkstra's >famous letter, but it's close. actually, i think that everyone ought to go back and look at Dijkstra's letter (geez, it's been 9 years since i read it) and at some of the surrounding debate at the time ... as i recall, Dijkstra was offering the observation that as an experiment he and some collegues had started a systematic effort to clarify a large algol 60 code, and noticed that as the number of goto's declined, the number of bugs went down. little did he know what a monster he had created ... at this point in time, after some 16 years of programming, the principle observations i have to offer is that if you are `forced' to use a goto, then somebody (either you, or your manglement, or that guy you inherited the code from who got fired two weeks before you started your job) probably made a bad decision. there are occasions for gotos, but they almost never arise in well-designed and well-implemented systems. also, goto is NEVER a good substitute for a well-designed and well-integrated exception-handling system. note that i am excluding `structured programming using gotos' as described in Knuth's article; in pre-fortran 77 days when i coded in fortran i generally coded according to Knuth's methods once i had learned about them. as for basic, which started all of this flamage, my personal feeling is that all basic programmers should be taken out and shot, in order to put them out of their misery. finally, i offer my own solution to the `sex' problem, in Common Lisp (all this C is doing bad things for my digestion.) Oh, yes -- it also uses the MIT Loop macro (i can see you lisp purists wincing out there.) this is, i believe, the original (i pinched this from Jerry Hollombe's article, and am assuming it it the original.) } printf ("Enter your sex: "); } while (sex != "m" && sex != "f") { } gets (sex); } if (sex != "m" && sex != "f") } printf (" or only: "); } } the above is a truly ugly piece of code, and i don't believe that it really works, although i haven't written more than 30 lines of C in the past 3 years. the following was tested in lucid cl version 3.0.2, by the way, and works perfectly. (defun get-sex (&optional (stream *terminal-io*)) "queries for user's sex on stream. returns nil if premature eof encountered premature ejaculation condition not handled" (write-line "Enter your sex (m or f)" stream) (loop for sex = (read-line stream nil nil) when (null sex) return nil ; eof error when (or (string-equal sex "m") (string-equal sex "f")) return sex do (write-line "m or f only please"))) it would look uglier without the loop macro; something like the following version which uses the simple common lisp loop (note that (return ) in common lisp is roughly comparable to C's break statement, except that being function-oriented, lisp returns a value): (defun get-sex (&optional (stream *terminal-io*)) "queries for user's sex on stream. returns nil if premature eof encountered premature ejaculation condition not handled" (write-line "Enter your sex (m or f)" stream) (let (sex) (loop (setq sex (read-line stream nil nil)) (when (null sex) (return nil)) (when (or (string-equal sex "m") (string-equal sex "f")) (return sex)) (write-line "m or f only please")))) enough of this nonsense, richard -- richard welty welty@algol.crd.ge.com 518-387-6346, GE R&D, K1-5C39, Niskayuna, New York ``Quotes and commas and backquotes, oh my''