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: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Software landmines (loops) Date: 1998/09/04 Message-ID: #1/1 X-Deja-AN: 387846201 References: <902934874.2099.0.nnrp-10.c246a717@news.demon.co.uk> <6r1glm$bvh$1@nnrp1.dejanews.com> <6r9f8h$jtm$1@nnrp1.dejanews.com> <6renh8$ga7$1@nnrp1.dejanews.com> <6rf59b$2ud$1@nnrp1.dejanews.com> <6rfra4$rul$1@nnrp1.dejanews.com> <35DBDD24.D003404D@calfp.co.uk> <6sbuod$fra$1@hirame.wwa.com> <35f51e53.48044143@ <904556531.666222@miso.it.uq.edu.au> <6sgror$je8$3@news.indigo.ie> <6sh3qn$9p2$1@hirame.wwa.com> <35EC1B94.CAC23CB3@tisny.com> <6si1rm$649$1@hirame.wwa.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-04T00:00:00+00:00 List-Id: In article gio+van+no+ni+8@tal+star+spam.com (Giovanni 8) writes: > I've run across this, too. Back before interactive debuggers > it was common to use gotos to reach a "normal" return, that, > with debugging turned on in the pre-compiler, would generate > a sort of trace log. But even there, it has the disadvantage > of covering up the "actual" point from which one is returning. > Why not deal with error handling right there, where the most > information is available? I think we are geting to the point of violent agreement. The "structured" code: <> loop Get(Next); if Next /= null; [lots of normal case code] else exit; end if; end loop; or <> Get(Next); while Next /= done loop [lots of normal case code] Get(Next); end loop; should be regarded as broken while the equivalents: <> loop Get(Next); if Next = null then exit; else [lots of normal case code] end if; end loop; or <> loop Get(Next); exit when Next = null; [lots of normal case code] end loop; or <> while Get(Next) loop; [lots of normal case code] end loop; are winners. The chief reason the first examples should be regarded as broken is that they result in one conceptual action being split often across several pages. Either the maintainer has to find two widely separated calls to Get that are really the same call, or you have to flip through several pages of code to find out where the then part of the if ends. Either can lead to errors. Among those marked as good, we can argue all year as to which is best, but in reality who cares. If maintaining that code, we will all be looking elsewhere for problems. I happen to prefer Good2 and those with a strong C background, or programming in C or C++ will probably prefer Good3. (In Ada you have to add a level of indirection so that the (now function) Get can modify its argument, and the new value is a side effect while the function actually returns a boolean. For Ada programmers this idiom is somewhat distateful, but in C it is almost standard.) Other languages favor other styles. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...