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,e01bd86884246855 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,fb1663c3ca80b502 X-Google-Attributes: gid103376,public From: David Kristola Subject: Re: Design by Contract (was Re: Interesting thread in comp.lang.eiffel) Date: 2000/07/17 Message-ID: <01HW.B59822A20005ECF4078EC70C@news.pacbell.net>#1/1 X-Deja-AN: 647267352 Content-Transfer-Encoding: 7bit References: <8ipvnj$inc$1@wanadoo.fr> <8j67p8$afd$1@nnrp1.deja.com> <395886DA.CCE008D2@deepthought.com.au> <3958B07B.18A5BB8C@acm.com> <395A0ECA.940560D1@acm.com> <8jd4bb$na7$1@toralf.uib.no> <8jfabb$1d8$1@nnrp1.deja.com> <8jhq0m$30u5$1@toralf.uib.no> <8jt4j7$19hpk$1@ID-9852.news.cis.dfn.de> <3963CDDE.3E8FB644@earthlink.net> <3963DEBF.79C40BF1@eiffel.com> <396502D2.BD8A42E7@earthlink.net> <39654639.B3760EF2@eiffel.com> <85Fa5.11419$7%3.818927@news.flash.net> <01HW.B591811303737A0605DE478C@news.pacbell.net> <396C7F14.563F1BA4@lmco.com> <8kl0r6$2lp6o$1@ID-9852.news.cis.dfn.de> <01HW.B59443DD000A71F808C44DCC@news.pacbell.net> <8kt1eb$34jh1$1@ID-9852.news.cis.dfn.de> Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 963826828 63.194.212.92 (Mon, 17 Jul 2000 02:40:28 PDT) Organization: heaps of stacks User-Agent: Hogwasher 2.0 (Macintosh) MIME-Version: 1.0 NNTP-Posting-Date: Mon, 17 Jul 2000 02:40:28 PDT Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 2000-07-17T00:00:00+00:00 List-Id: On Sun, 16 Jul 2000 12:12:10 -0700, Joachim Durchholz wrote (in message <8kt1eb$34jh1$1@ID-9852.news.cis.dfn.de>): > David Kristola wrote: >> On Thu, 13 Jul 2000 11:12:53 -0700, Joachim Durchholz wrote: >> >>> or >>> find_minimum_in (h: HEAP) >>> require >>> not h.is_empty >> >> Depending on the implementation of the heap, this too would >> probably cause some sort of exception to be raised if the >> heap were empty. > > The difference is that the exception will happen before the routine is even > called. The responsibility for the exception will clearly be the caller's. > If the exception happens somewhere inside the routine, you need another > analysis stept to find out which part of the code is really responsible for > the problem. Perhaps it is my coding style, but (in this limited case) i would consider it the responsibility of the caller to handle the exception. There is nothing find_minimum_in can do if the heap is empty. To me, that is even an unstated but obvious contract. This is not to say that it is not worth stating obviously and in a way that can be checked by a compiler. This particular example is perhaps a little simple. Certainly there are plenty of others that are not so obvious, where a formally stated precondition adds to the understanding. Unlike some other areas, i can't think of a way to define a subtype of heap that only contains non-empty heaps. Ada also does not provide for the inheritance of contracts. That is a very interesting aspect of Eiffel. -- --djk, keeper of arcane lore & trivial fluff Home: David95036 plus 1 at america on-line Spam: goto.hades@welovespam.com