Xref: utzoo misc.misc:5963 comp.misc:5965 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!philmtl!philabs!ttidca!hollombe From: hollombe@ttidca.TTI.COM (The Polymath) Newsgroups: misc.misc,comp.misc Subject: Re: The "evil" GOTO (Was: 25 Years of BASIC) Keywords: Guinness, phlegm, mackerel, intestines Message-ID: <4373@ttidca.TTI.COM> Date: 5 May 89 19:29:25 GMT References: <1791@ubu.warwick.UUCP> <1436@onion.reading.ac.uk> <1814@ubu.warwick.UUCP> Reply-To: hollombe@ttidcb.tti.com (The Polymath) Organization: The Cat Factory Lines: 75 In article <1814@ubu.warwick.UUCP> mirk@uk.ac.warwick.cs (Mike Taylor) writes: }In article <3, I think> gould@rosemary.cs.reading.ac.uk (Adrian Gould) writes: }> Lets eradicate the GOTO from all languages. } }I hate it when people say things like that; As if you can just wave a }magic wand over a language by excising GOTO, and everything will be }alright. Listen, just 'cause Quiche-eater Wirth connected GOTOs with It was Dijkstra. }lack of structure geenrally, doesn't mean either that (A) ALL use of }GOTO is unstructured and obfuscatory, or that (B) ALL obfuscated code }is due to use of GOTO ... }How many times have you seen this kind of code? } } printf ("Enter your sex: "); } while (sex != "m" && sex != "f") { } gets (sex); } if (sex != "m" && sex != "f") } printf (" or only: "); } } } Thankfully, not very often (but then, I haven't got around to teaching an intro to programming course, yet). Here's how it should be done: do { printf ("\nEnter your sex (m or f): ") if (EOF == (sex = getchar()) perror ("getchar() error"); } while ((sex != 'm') && (sex != 'f')) Generally, a little thought and analysis can eliminate the need for nearly all GOTOs quite elegantly. }... How many times have you seen people using "for (;;;) ... }break;" when you *know* that by "break" they mean "GOTO"? ... If they'd meant goto they'd have said goto. The construct does exist in C. "break" is not equivalent. It's much more limited and less likely to get you into trouble. }... In many }situations GOTO is natural ... In a few situations it has its uses. }... Clearly irresponsible use of }GOTO is bad; clearly spaghetti-junction programs written in languages }with no other flow-control are bad (Frog knows how APL people manage!) }But let's get this in perspective. It isn't GOTO's fault. It's yours }for using it badly. True. The best quote I've heard on the subject was from some CS lecturer: "I sometimes use GOTOs. I also use guns. I _don't_ let children play with them." }It makes me laugh when people push Ada as a good real-time langauge }because iof its "powerful exception-handling". "Exception-handling". }Do you know what that means? Yup, you guessed it, it's a fancy word }for GOTO. ... No, it isn't. As I recall, it's much closer to return(). An Ada function either has its own exception handler or it passes the exception back to the function that called it. -- The Polymath (aka: Jerry Hollombe, hollombe@ttidca.tti.com) Illegitimati Nil Citicorp(+)TTI Carborundum 3100 Ocean Park Blvd. (213) 452-9191, x2483 Santa Monica, CA 90405 {csun|philabs|psivax}!ttidca!hollombe