From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,9a0ff0bffdf63657 X-Google-Attributes: gidfac41,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Software landmines (was: Why C++ is successful) Date: 1998/08/16 Message-ID: #1/1 X-Deja-AN: 381676634 References: <6qfhri$gs7$1@nnrp1.dejanews.com> <35cb8058.645630787@news.ne.mediaone.net> <902934874.2099.0.nnrp-10.c246a717@news.demon.co.uk> <6r1glm$bvh$1@nnrp1.dejanews.com> X-Complaints-To: usenet@news.nyu.edu X-Trace: news.nyu.edu 903282037 21474 (None) 128.122.140.58 Organization: New York University Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-08-16T00:00:00+00:00 List-Id: T.E.D says For a simple loop, embedding the rest of the loop code in the body of the if statement is clearer. For nested loops where you want to "continue" an outer loop, I can see it. Not that I'd do such a thing. Even in the simple case: for J in 1 .. N loop if D (J) = NaN then goto Continue; end if; giant section of code <> null; end loop; as opposed to for J in 1 .. N loop if D (J) /= NaN then giant section of code end if; end loop; there may be a preference for the goto. It shows the reader right up front that the loop does nothing at all to NaN's, without having to match up the if with the end if at the end of the giant section of code to know this. Also, it means that the giant section of code has one less level of indentation. But it's a toss up in this case, and for most purposes we would prefer the second case. Where it gets tricky is for J in 1 .. N loop if condition 1 then ... if condition 2 then ... if conditoin 3 then goto Continue; Now T.E.D's prescription is not so clear, and we end up having to severely contort things, or introduce a boolean flag which we keep testing as we unwind to the end. Remember that the continue here is just like a return. If you are allergic to using a loop continue or exit, you should be allergic to using a return (other than at the end of a function). Some people are, and that is at least consistent. But I see a lot of Ada programmers who will use a return without hesitation from a nested loop, but still turn green at the sight of a goto. That makes no sense to me. As a "goto-holic" who has been straight for 10 years, the best bet is abstinence. One day at a time. :-) Maybe the comparison is apt. If you really are unable to figure out how to use gotos properly, then perhaps abstinence is the "best bet", but just as we know that wine drunk in moderation can actually be a health benefit, and is most certainly not a health danger, the occasional use of a goto can be beneficial for the clarity and efficiency of your code. We can appreciate and sympathize with the poor goto-holic's who may not risk this, but it does not mean the rest of us have to abstain :-) So the "average" poor maintainer schlep looks at this and thinks "is this just a continue, or a complete restarting of the loop?" Oh yeah, that's clear. %-( The idea that code can ever be maintained by incompetent shlep's who do not understand the language they are writing in is of course a serious error. Yes, I know it happens, look at the results, need I say more? On the other hand, I see no reason to accept this rhetoric, if indeed you do have these poor maintainer shleps looking at the code, we have only T.E.D.'s unsupported allegation that they will have more trouble with my form than some other form (note that, perhaps wisely, T.E.D does not attempt to demonstrate the beautifully clear, alternative, goto-free form -- enough other competent people have tripped on that already :-) If anyone does something this bizzare, they'd better put copious comments around it explaining its semantics. Otherwise, its the software equivalent of a land mine. Its just sitting there waiting for someone to touch it, then ...BOOM! Well of course any code needs commenting, and pointing out the critical details of the algorithm in use, especially if, as in this case, it is likely to be an unfamiliar algorithm, is definitely a good idea. Very good counterexample to your own point. I don't think so!