Xref: utzoo misc.misc:6048 comp.misc:6031 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-lcc!ncis.tis.llnl.gov!lll-winken!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!roemer From: roemer@cs.vu.nl (Roemer Lievaart) Newsgroups: misc.misc,comp.misc Subject: Re^2: The "evil" GOTO (Was: 25 Years of BASIC) Message-ID: <2468@solo9.cs.vu.nl> Date: 9 May 89 11:31:16 GMT References: <905@twwells.uucp> <13301@lanl.gov> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 57 In article <13113@lanl.gov> jlg@lanl.gov (Jim Giles) writes: > if (cond1) { > [...A...] /* lots of code */ > goto LABEL;} > else if (cond2) { > LABEL: [...B...] /* lots more code */ > } > Ugh. I would choke on this several times if I would have to maintain this. And I know what I am talking about, for I sometimes use goto's if I haven't planned everything well in advance. But only in very simple cases (like the one described). When reading such code over again, I *always* end up confused, even a week after I wrote it. BTW. Why not: if (cond1 || cond2) { if (cond1) { [...A...] } [...B...] } Simple and neat. And understandable: B is done if cond1 or if cond2, A only if cond1. In the goto-version this is not clear immediately (to me it isn't!) Of course, if cond1 has side-effects or is very complicated, one should read: bool condition1; condition1 = cond1; if (condition1 || cond2) { if (condition1) { [...A...] } [...B...] } People may throw up at throwing in extra variables like this. I used to. Until I discovered that if you *name* them right, they really even make things much *easier* to read. Variable naming is very important, especially in cases like these. The problem with goto's is: When you don't use them often, you have troubles reading or maintaining code which has them. If you do use them often, you're very probably writing spaghetti code. -- Roemer ____________________________________________________________________________ Roemer B. Lievaart | LISP : Amsterdam, Holland | a Lot of Irritating, Stupid Parenthesis roemer@cs.vu.nl |