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: dennison@telepath.com Subject: Re: Software landmines (loops) Date: 1998/08/31 Message-ID: <6sebjr$b69$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 386426392 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> <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> X-Http-Proxy: 1.0 x5.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Mon Aug 31 14:22:51 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-08-31T00:00:00+00:00 List-Id: In article <6sbuod$fra$1@hirame.wwa.com>, "Robert Martin" wrote: > > Matthew Heaney wrote in message ... > > >This theory was indeed put to the test, and guess what? Programmers > >using a test-and-exit from the middle of the loop produced fewer errors > >than those programmers who tried to put the test at the top of the loop. ... > >The goodness of a language construct should not be determined by > >doctrinaire computer scientists or mathematicians. The only thing that > >matters is whether working programmers think it's easier to understand, > >and whether by using the construct programmers inject fewer errors into > >the code. > > And whether or not the construct is maintainable over the long term. There > are lots of constructs that make writing the initial program easy, but make > maintaining it hard. The practice of using such constructs, i.e. ignoring > long term effects, is sometimes called "hacking". I gave up mangling my code to make while loops years ago for just the reason Matthew spoke of. Occasionally when I make a middle-exited loop I will try to make a while loop out of it, but I almost always delete the code and go back to the middle-exited loop. If an algorithm really is a middle-exited loop, you just confuse things (thereby making the code harder to understand) by tring to force a different structure on it. For me, the extra code is a prime source of errors as well. Continuing with my example of a naturally middle-exited loop, there are really only two ways of "whileing" it. The first is to "unroll" one half of an iteration (up to the test). The problem with that is now you have duplicated code. In practice I find the odds of having to change that code and forgetting to change it both places is distressingly high. The other option is to create a flag of some sort, and check it every loop iteration. That's even worse because I have increased the (McCabe) complexity of the code to a rather non-obvious end. If I have to add code to the loop, even I the author have to think hard about where it goes now. Also, getting the logic on a flag reversed is one of my most common errors. I never seem to fail to do that one if given a chance. In fact I just fixed one of those yesterday. Additionally, there is the run-time issue. You are adding a check into every iteration of the loop that will go one way nearly every time. Sometimes that can get optimized out, but I wouldn't count on it. I will admit that a naturally top-exited loop written with a top-eixted loop construct is easier to understand than a naturally middle-exited loop written with a middle-exited loop construct. But that does *not* mean that the naturally middle-exited loop would have been easier to understand if twisted to use the top-exited construct too. As always, YMMV. -- T.E.D. -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum