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: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public From: dennison@telepath.com Subject: Re: Software landmines (loops) Date: 1998/09/02 Message-ID: <6sjjov$j7d$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 387124282 References: <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@news.erols.com> <6sdiav$e0g$1@hirame.wwa.com> <6sfcft$70p$1@hirame.wwa.com> <6shp40$ec8$1@nnrp1.dejanews.com> <6sie46$eb7$1@hirame.wwa.com> <6siijm$h1m$1@hirame.wwa.com> X-Http-Proxy: 1.0 x8.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: Wed Sep 02 14:12:47 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 <6siijm$h1m$1@hirame.wwa.com>, "Robert Martin" wrote: > > Of course later on, someone asks us to sieze and release a mutex for each > iteration of the loop. We'd like to put the seize as the first line of the > loop body, and the release as the last line of the loop body. But if there > are early exits, then we must put a release before every exit. > > Of course later on someone adds yet another early exit to the loop, and must > remember to bump the counter and release the mutex. > > .... Has anybody out there ever had an experience like this? In my experience it is more likely that I'm going to have to either add code to one of the branches that doesn't always get executed, or create a new (non-exiting) if-conditional inside the loop. In both cases my cause is helped greatly by not having a lot of extra conditional code already in the loop. But if the loop is naturally middle-exiting, then you will HAVE to have that coditional code in the loop (or have one copy of it outside the loop, which is a problem as well). Part of my problem is that a conditional in a loop tells me "this code can execute some iterations and not others". I have to go figure out exactly when by examining the entire loop to see what affects the conditional, and all the preceeding code to figure out its initial condition. I have to do a *lot* of digging just to figure out that it once it is false, it will never be true again. Using an "exit" or "return" tells me that information up front. I'm inclined to believe that the construct that conveys the most information about what I am doing is going to be the one that makes reading and maintainence easiest. Now I will freely admit that someone could embed lots of returns and exits within different levels of if statements and inner loops, and make a completely confusing mess. In that case, yes switching to flags would probably be better. But as long as the overall structure of the loop is simpler with the early exit construct, I don't see why it shouldn't be used. -- 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