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: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: ell@access.digex.net (Ell) Subject: Re: Software landmines (loops) Date: 1998/09/04 Message-ID: <35f1375e.6237208@news.erols.com>#1/1 X-Deja-AN: 387679372 Content-Transfer-Encoding: 7bit References: <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> <6simjo$jnh$1@hirame.wwa.com> <6sjk3p$4tc$1@hirame.wwa.com> <6skgn4$3gq$1@hirame.wwa.com> <6sm6md$3fh$1@hirame.wwa.com> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@rcn.com X-Trace: winter.news.erols.com 904871218 23930 207.172.183.153 (4 Sep 1998 01:06:58 GMT) Organization: Universe Mime-Version: 1.0 Reply-To: ell@access.digex.net Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-04T00:00:00+00:00 List-Id: "Robert Martin" wrote: >Matthew Heaney wrote in message ... >> >>"Robert Martin" writes: >>> >>> for(;;) >>> { >>> Get(N); >>> if (N) >>> >>> else >>> break; >>> } >>> >>Boy oh boy, Robert, we must come from different programming schools! >And that's part of the point I'm trying to make. There is no single >readability standard. We all come from different schools in some way or >another. So what you think is readable, will not be as readable to me, or >to someone else. But generally it is possible to get a plurality or majority to agree on what is readable. In most cases readability decisions are made by polling project developers where I work and have worked in the past. You have to go with something, why not the plurality, or majority? >>The dangerous thing about the code fragment above is that the else part >>can get lost, especially if is long-ish. >> >>My philosophy is, handle the simple case first, then bail out: >> >> for (;;) >> { >> Get (N); >> >> if (!N) break; >> >> >> } Makes imminent sense to me. >Ask yourself why 'break' is the most important concept of this function? >Why is it more important to get the exceptional conditions out of the way >first rather than to get right into the actual purppose of the function. > >I prefer a style that moves into the real action of the function as quickly >as possible, while deferring the exceptional conditions to the end. I advocate that in general we should test to see that pre-conditions are met, and if they aren't, bail. Why even try to process if pre-conditions have not been met? if (!pre-condition) bail else do_processing() endif Elliott >Consider this, would you prefer that catch statements *precede* try blocks? > >catch(memerr) >{ >} >catch(fileerr) >{ >} >try >{ >} Testing for pre-conditions before processing is not equal to what the try/catch idiom is about. 'catch' is about catching *exceptions* which occur *within* 'try' processing. It is not about testing *pre-conditions* to what is necessary for successfully processing in a block. The difference is that exceptions in processing may legitimately occur even though pre-conditions for processing have been met. N'est ce pas? Elliott