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: 103376,f66d11aeda114c52 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Building blocks (Was: Design By Contract) Date: 1997/10/03 Message-ID: <3434F608.3E02@gsfc.nasa.gov>#1/1 X-Deja-AN: 277603511 References: <34316EC3.5B62@dynamite.com.au> <199710011402.QAA02444@basement.replay.com> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-10-03T00:00:00+00:00 List-Id: Robert A Duff wrote: > By the way, speaking of negative logic, what do people think about > negative logic in "if" statements? I tend to try to reduce the number > of "not"s in the code. But other people tend to use some other > heuristic, such as "do the normal case first" or "do unusual case > first". For example: > > if Is_Evil(X) then > print error message; > else > ... -- 37 lines of code doing the normal thing > end if; I prefer this style; put the easily handled case first. > > vs > > if not Is_Evil(X) then > ... -- 37 lines of code doing the normal thing > else > print error message; > end if; > > vs > > if Is_Good(X) then > ... -- 37 lines of code doing the normal thing > else > print error message; > end if; > > vs > > if not Is_Good(X) then > print error message; > else > ... -- 37 lines of code doing the normal thing > end if; > > Or perhaps even: > > if Is_Evil(X) then > print error message; > return; > end if; > ... -- 37 lines of code doing the normal thing I also do this, especially when the 'return' gets me out of more than one layer of 'if' > > - Bob -- - Stephe