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: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: Is there a language that Dijkstra liked? (was: Re: Software landmines (loops)) Date: 1998/10/29 Message-ID: #1/1 X-Deja-AN: 406252460 References: <718lct$qk1$1@supernews.com> Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: The hebrew University of Jerusalem Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-29T00:00:00+00:00 List-Id: On Wed, 28 Oct 1998, Pat Rogers wrote: > One does have to be careful, though. Consider: > > function Next( This : Some_Discrete_Type ) return > Some_Discrete_Type is > begin > return Some_Discrete_Type'Succ(This); > exception > when Constraint_Error => > return Some_Discrete_Type'First; > end Next; > > In such cases the explicit, hand-coded check is > preferable, IMHO: > > function Next( This : Some_Discrete_Type ) return > Some_Discrete_Type is > begin > if This = Some_Discrete_Type'Last then > return Some_Discrete_Type'First; > else > return Some_Discrete_Type'Succ(This); > end if; > end Next; > In this example, I for one would think both approaches are viable. Maybe I would even prefer the IF approach. This is not the example for misusing valdity checks. What I find ugy is things like this: i:integer if i<0 then instead of i:Natural This kind of coding style doesn't allow the reader to stop checking for himself the i is indeed always non negative. Ehud Lamm mslamm@mscc.huji.ac.il