Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!lll-winken!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.pascal Subject: Re: Gotos are ok (Was Re: IMPLEMENT GOTO ACROSS MODULES IN TURBO PASCAL??) Message-ID: Date: 25 Jan 91 07:05:05 GMT References: <2802@oucsace.cs.OHIOU.EDU> <1991Jan21.134342@cs.utwente.nl> <2427@bnlux0.bnl.gov> <21489@oolong.la.locus.com> Sender: news@skipper.dfrf.nasa.gov Organization: NASA Dryden, Edwards, Cal. Lines: 82 In-reply-to: jfr@locus.com's message of 24 Jan 91 17:38:35 GMT On 24 Jan 91 17:38:35 GMT, jfr@locus.com (Jon Rosen) said: Jon> can ONLY goto to a SINGLE place... I.e., in the abstract, the programmer Jon> can't make a mistake... Jon> Jon> In the following pseudo-code: Jon> Jon> Repeat... Jon> ... Jon> if ... then leave; Jon> ... Jon> EndRepeat; Jon> Jon> There is only ONE place the leave statement can place the program... Jon> That is after the EndRepeat statement... The programmer can only ^^^ (as in THE only such statement anywhere?) Jon> make a mistake in his logic (does he really want to LEAVE this Jon> loop at this time?)... He can make NO mistake in his syntax... I wasn't going to enter this religious discussion, *but* I think there is a factual error in the above. The goto and the exit are subject to simillar problems. You could just as legitimately have said "There is only one place the goto statement can place the program... That is after the label." Both your statement and my modification ignore the important point that there may be multiple EndRepeat statements or multiple labels. (Actually I don't think "syntax" is the right term for the class of errors you are talking about, but your meaning is reasonably clear even if the word isn't quite right). In some ways (not all, I agree) the above code is *more* prone to errors than the equivalent using goto. Suppose, for instance, I have the above code working but later decide to add a repeat..endrepeat loop to handle an input error check (or whatever). If I don't look carefully, the code becomes Repeat (the original one) ... Repeat (the added one) ... if ... then leave ... EndRepeat ... EndRepeat Instant bug. I don't think this is particularly esoteric either. I've done it and I've seen others do it. In this particular case, the goto construct would not have been as prone to the problem. Now if the original had been in Fortran 90 (hmm, is my religion showing?) and looked like the_loop: do ... if (...) exit the_loop ... end do the_loop then the odds of introducing errors would be lower I'd think. For my part, well Fortran is my major language (for various reasons, some of which are just my religious preferences, and others of which are more objective, but all of which are irrelevant here). It's really hard to do ANSI standard Fortran 77 code without gotos. Not impossible, but hard and awkward enough that I don't try. So of course I use gotos, but I do use them with discipline. (Well, anyway I think so). I Fortran 90, which I've started dabbling with in anticipation of compilers coming out, I use far fewer gotos because the language has constructs like the above example. Yes, I know the above exit is a goto in disguise, but its a disguise that I find useful. Fewer is not the same as none. Yes, I know you Pascal types don't really care much about the Fortran aspects of the above. -- Rich Maine maine@elxsi.dfrf.nasa.gov