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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: fac41,9a0ff0bffdf63657 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public From: Nick Leaton Subject: Re: Software landmines (loops) Date: 1998/09/09 Message-ID: <35F65BA6.D4709D8A@calfp.co.uk>#1/1 X-Deja-AN: 389345156 Content-Transfer-Encoding: 7bit X-NNTP-Posting-Host: calfp.demon.co.uk:158.152.70.168 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> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 905337809 nnrp-04:2889 NO-IDENT calfp.demon.co.uk:158.152.70.168 MIME-Version: 1.0 Reply-To: nickle@pauillac Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-09T00:00:00+00:00 List-Id: Giovanni 8 wrote: > > > Robert I. Eachus wrote: > >> Giovanni 8 wrote: > >> 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; > >... > > 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; > > Great, if the "Get" knows what abnormal conditions to handle > for this particular context (module, function, whatever), & > then one would work in other "normal" conditions, as well. > > This reminds me of reading Wirth's _Systematic Programming_. > He presented these pat examples, to which few common problems > could be made to conform. (Even his "proof" of a GCD > algorithm just kind of brushed past a crucial point.) > > It's more like > loop > { > Get(Next); > if (thiscondition) then > { > do this; > return; > } > else if (thatcondition) then > { > do that; > return; > } > else if (theother) then > { > do goodstuff; > } > else if (yetanother) then > { > do othergoodstuff; > } > else > do unforeseencondition; > endif > do morestuff > } > endloop when(x); > do aftertheloopstuff > return; > > Yes, it's defensive programming. Enlighten me. So lets say the loop calculates a square root. What should 'do this' and 'do that' do? What if it is in an aircraft, in a simulation? Do you want to rewrite square root for each case? -- Nick