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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, TO_NO_BRKTS_FROM_MSSP 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: Phil Goodwin Subject: Re: Software landmines (loops) Date: 1998/09/02 Message-ID: <6sk01j$1qn$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 387175662 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> <6sf87j$47n$1@hirame.wwa.com> <6shp1i$ead$1@nnrp1.dejanews.com> <35EC937F.94420C51@ibm.net> X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 38.222.136.64 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Wed Sep 02 17:42:12 1998 GMT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I) Date: 1998-09-02T00:00:00+00:00 List-Id: In article <35EC937F.94420C51@ibm.net>, bijuthom@ibm.net wrote: > Phil Goodwin wrote: > > > > I write plenty of little routines that have loops in them that exit in the > > middle. It doesn't make sense to me to alter the algorithm and write extra > > code just so that the routine might be easier to maintain someday (if ever). > > On the other hand, when I DO maintain such a routine I definitely WILL make > > sure that there is only one exit point if that's what is needed to eliminate > > duplicate code. > > > > I adopted this position in part because of some of what I've read about > > Extreme Programming. I haven't adopted it wholesale, but I do like their > > no-nonsense philosophy. They use two balancing maxims that I've applied to > > this question: Do The Simpest Thing That Could Possibly Work; and Once And > > Only Once. So when I write a function I do the simplest thing that could > > possibly work, which sometimes means sticking a return right smack in the > > middle of a loop. I am especially likely to do this when the loop body is > > less than five lines long anyway. Then, when I have to refactor in order to > > add the aquisistion and release of some resource, I rearrange the routine so > > that I add the code once and only once. The justification for this is that I > > don't want to adopt a coding task because it _might_ be needed during > > maintenance, I would rather do it during maintenance when I KNOW that it > > needs to be done. > > The problem with such refactoring during maintenance is that it may > introduce new problems, and you need to do extensive testing to make > sure that you haven't broken anything. Often, this type of extensive > testing may not be feasible at all during maintenance, because of budget > and time constraints. This type of attitude may explain why new releases > of software (which are supposed to do bug fixing too) introduce more > bugs than the original version. I would posit that if you are changing the function at all you must do a complete regression test on it. I grant you that the more you change the routine the more likely you are to introduce bugs and that is an important consideration. However, what we are doing here is deffering the risk of creating a more complicated algorithm to the point in time where we know that the risk is worthwhile. The only other option is to assume that the risk will always turn out to be worthwhile and code the more complicated algorithm in every case. Since we know that we aren't going to reap the benefit of the complicated algorithm in every case we can surmise that we have done too much work. My position is not that strict structured programming has no benefit, it is that it has a cost and that the cost is not justified unless the benefit is recieved. The strategy I outlined is designed to defer the cost until the benefit reaches its highest value. Phil -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum