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: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Software landmines (loops) Date: 1998/09/03 Message-ID: #1/1 X-Deja-AN: 387654166 References: <6sf4gl$hb6@flatland.dimensional.com> <6siqo0$hiv@flatland.dimensional.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-03T00:00:00+00:00 List-Id: In article <6siqo0$hiv@flatland.dimensional.com> jtc@dimensional.com (Jim Cochrane) writes: > Looking at your routine, you need to check 3 different places to check that > the postcondition is upheld, the 3 return statements: In the first if > statement, in the second if statement in the middle of the loop, and at the > end of the routine. This is a pretty straightforward process, but I think > it makes it a little more difficult in that you need to check 3 separate > locations, including in the middle of the loop. But this is irrelevant to the way the code was written, and to the way it should be understood. The code flows from this problem statement: "Two lists are equal if they are the same length and each element in the first list is equal to the corresponding element in the second list." Now the postconditions corresponding to the three exits are: Lengths not equal, lists not equal. Element L.Items(Index) /= R.Items(Index), lists not equal. Lengths and all elements equal, lists are equal. Before you jump all over me, realize that this is a DIFFERENT way of treating postconditions, factoring the full statement of the postcondition into separate cases, and having an exit/return for each case. There are many cases where it results in the best code, there are others where it is not the method of choice, but if you are willing to accept multiple returns, then you should add this approach to your bag of tricks. (Notice that it works best when you can linearize the cases as you can here.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...