comp.lang.ada
 help / color / mirror / Atom feed
From: jcm@hgc.edu (James McKim)
Subject: Re: Eiffel and Java
Date: 1996/11/04
Date: 1996-11-04T00:00:00+00:00	[thread overview]
Message-ID: <1996Nov4.174332.790@merlin.hgc.edu> (raw)
In-Reply-To: mheaney-ya023180000111962205520001@news.ni.net


In article <mheaney-ya023180000111962205520001@news.ni.net> mheaney@ni.net (Matthew Heaney) writes:
>In article <1996Oct31.201748.29073@merlin.hgc.edu>, jcm@hgc.edu (James
>McKim) wrote:
>
>>>>Ada's type mechanism accomplishes the equivalent of pre- and
>>>>post-conditions, and you don't seem to mind their inclusion in Eiffel, so
>>>>that can't be it.
>>>
>>>Well, to some extent... I admit you can easily use pre and post conditions in 
>>
>>Whoa, about the simplest precondition I can think of is related to accessing
>>the top of a generic stack.
>>
>>class STACK[G]
>>...
>>  top : G is
>>  require
>>    not_empty: depth > 0
>>...
>>
>>How do you emulate this using types in Ada? 
>
>Perhaps I didn't make my original point clear.  The designers of Ada 95
>considered including some precondition/postcondition checking in the
>language (as Eiffel does), but opted not to because Ada's rich typing
>mechanisms already provide "some of" that.

Well, I've lost track of who said what. "some of" I'll buy, but I quarrel 
with either "equivalent of" (from the first line above) or "much of"
(from another poster in this thread) I quarrel with.


[... Nice example of a compass elided ...]

>
>That subtype constraints are a form of pre- and post-condition it what I
>was trying to say.  Please note that I like Eiffel and think its facilities
>for checking assertions, pre-, and post-conditions are way cool and yes, I
>really would like something like that in Ada.  Perhaps for the next
>revision of the language.

:-) FTR, Ada has some good stuff that Eiffel is currently missing, e.g.
threads.

>
>As for how to assert precondition that a stack be non-empty, I can already
>do that in Ada:
>
>generic
>   type T is private;
>package Bounded_Stacks is
>
>   type Stack (Size : Positive) is limited private;
>
>   function Top (S : Stack) return T;
>
>...
>
>private
>
>   type Item_Array is array (Positive range <>) of T;
>
>   type Stack (Size : Positive) is
>      record
>         Items : Item_Array (1 .. Size);
>         Top : Natural := 0;
>      end record;
>
>end;
>
>package body Stacks is
>
>   function Top (S : Stack) return T is
>   begin
>      return S.Items (S.Top);
>   end;
>...
>end;
>
>If the stack is empty, then S.Top = 0 and the call to function Top will
>(automatically) raise Constraint_Error, because the array index constraint
>was violated.
>
>Just like a precondition.
>
>If you don't like Constraint_Error, then put a handler for it in body of
>Top and raise the exception of your choice.
>

Well, "just like" is too strong I think.

1) As far as I can tell the precondition is not visible to clients without
your doing yet more work.

2) The error that is raised will not be a precondition error, it'll be
a constraint error as you note. I see you can fix this with a little
more work, but that extra work is what keeps it from being "just like"
a precondition check in Eiffel.

3) The exception will be raised in the the supplier, but the onus of precondition checks is on the client and that's where the exception would be 
raised in Eiffel.

4) Perhaps most importantly, if I change the implementation of the Stack
away from an ARRAY I'd have to do yet more work to make sure that an exception
is still generated at the appropriate time and with the appropriate message.
 
>--------------------------------------------------------------------
>Matthew Heaney
>Software Development Consultant
>mheaney@ni.net
>(818) 985-1271

Hope this helps,
-- Jim


-- 

*------------------------------------------------------------------------------*
Jim McKim  (860)-548-2458     Teachers affect eternity. They can never tell 
Internet:  jcm@hgc.edu        where their influence stops.




  reply	other threads:[~1996-11-04  0:00 UTC|newest]

Thread overview: 168+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-27  0:00 Eiffel and Java Vincent WEBER
1996-10-27  0:00 ` Jean-Michel P. Decombe
1996-10-28  0:00   ` Alexandre Oliva
1996-10-28  0:00   ` David Hanley
1996-10-28  0:00     ` Matt Kennel
1996-10-28  0:00   ` Robert Dewar
1996-10-31  0:00     ` Doug Marker
1996-10-29  0:00   ` Chris Trimble
1996-10-31  0:00     ` Doug Marker
1996-10-31  0:00   ` David Bennett
1996-10-28  0:00 ` Matthew Heaney
1996-10-29  0:00   ` Vincent WEBER
1996-10-31  0:00     ` James McKim
1996-11-01  0:00       ` Matthew Heaney
1996-11-04  0:00         ` James McKim [this message]
1996-10-30  0:00   ` Jon S Anthony
1996-11-01  0:00     ` Eiffel and Java + Ada dispatching Jean-Marc Jezequel
1996-10-30  0:00   ` Eiffel and Java Don Harrison
1996-10-31  0:00     ` James McKim
1996-11-04  0:00       ` Don Harrison
1996-11-23  0:00       ` Van Snyder
1996-10-31  0:00   ` Joachim Durchholz
1996-11-01  0:00   ` Norman H. Cohen
1996-11-02  0:00   ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-02  0:00   ` Eiffel and Java Jon S Anthony
1996-11-03  0:00   ` Joachim Durchholz
1996-11-05  0:00   ` Norman H. Cohen
1996-10-28  0:00 ` Larry Kilgallen
1996-10-30  0:00   ` Ronald Cole
1996-10-29  0:00 ` Don Harrison
1996-10-29  0:00   ` Fergus Henderson
1996-10-30  0:00     ` Don Harrison
1996-10-30  0:00       ` Fergus Henderson
1996-10-31  0:00     ` David L. Shang
1996-11-01  0:00       ` Matt Kennel
1996-11-04  0:00         ` David L. Shang
1996-11-05  0:00           ` Matt Kennel
1996-11-06  0:00             ` David L. Shang
1996-11-04  0:00       ` Robert I. Eachus
1996-11-01  0:00     ` Jon S Anthony
1996-11-02  0:00       ` Fergus Henderson
1996-11-04  0:00       ` David L. Shang
1996-11-05  0:00         ` Jon S Anthony
1996-11-02  0:00     ` Darko BUDOR
1996-11-02  0:00       ` Fergus Henderson
1996-11-03  0:00         ` Matt Kennel
1996-11-03  0:00         ` Darko BUDOR
1996-11-03  0:00     ` Matthias Ernst
1996-11-03  0:00     ` Jon S Anthony
1996-11-05  0:00     ` Jon S Anthony
1996-11-10  0:00     ` Marcos F. F. de Macedo
1996-11-11  0:00       ` David L. Shang
1996-11-12  0:00         ` Fergus Henderson
1996-11-12  0:00           ` David L. Shang
1996-11-12  0:00             ` David L. Shang
1996-11-16  0:00             ` Fergus Henderson
1996-11-18  0:00               ` David L. Shang
1996-11-18  0:00             ` Kai Quale
1996-11-18  0:00               ` David L. Shang
1996-11-25  0:00                 ` Kai Quale
1996-11-15  0:00         ` Paul Johnson
1996-11-12  0:00       ` Alexander Asteroth
1996-11-11  0:00         ` Marcos F. F. de Macedo
1996-11-12  0:00         ` Matt Kennel
1996-11-12  0:00         ` Benedict A. Gomes
1996-10-29  0:00   ` Eiffel and Java + Ada dispatching Vincent WEBER
1996-10-30  0:00     ` Don Harrison
1996-10-30  0:00       ` Jon S Anthony
1996-10-30  0:00     ` Jean-Marc Jezequel
1996-11-01  0:00       ` Don Harrison
1996-11-01  0:00       ` Joachim Durchholz
1996-10-30  0:00   ` Robert I. Eachus
1996-10-30  0:00   ` Jon S Anthony
1996-11-04  0:00     ` Don Harrison
1996-11-04  0:00       ` C to Ada Ali Mirhosseini
1996-11-04  0:00         ` Robert Dewar
1996-11-04  0:00         ` Matthew Daniel
1996-11-05  0:00       ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-05  0:00         ` Don Harrison
1996-11-06  0:00           ` Jon S Anthony
1996-10-30  0:00   ` Eiffel and Java David Petrie Stoutamire
1996-10-31  0:00   ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-01  0:00     ` Jean-Marc Jezequel
     [not found]     ` <E06F2B.Az7@syd.csa.com.au>
1996-11-01  0:00       ` Jon S Anthony
1996-11-04  0:00         ` Don Harrison
1996-11-05  0:00           ` Jon S Anthony
1996-11-02  0:00       ` Robert Dewar
1996-11-04  0:00         ` Norman H. Cohen
1996-11-05  0:00         ` Don Harrison
1996-11-05  0:00           ` Robb Nebbe
1996-11-06  0:00             ` Jean-Marc Jezequel
1996-11-07  0:00               ` Robb Nebbe
1996-11-06  0:00             ` To overload or not to overload (was Eiffel and Java + Ada dispatching) Don Harrison
1996-11-06  0:00               ` Robb Nebbe
1996-11-07  0:00                 ` Norman H. Cohen
1996-11-07  0:00                 ` Don Harrison
1996-11-07  0:00                   ` Juergen Schlegelmilch
1996-11-08  0:00                     ` Don Harrison
1996-11-08  0:00                       ` Don Harrison
1996-11-14  0:00                         ` Jon S Anthony
1996-11-14  0:00                     ` Jon S Anthony
1996-11-07  0:00                   ` Jon S Anthony
1996-11-07  0:00                   ` Jon S Anthony
1996-11-11  0:00                     ` Don Harrison
1996-11-08  0:00                   ` bill.williams
1996-11-11  0:00                     ` Don Harrison
1996-11-08  0:00             ` Eiffel and Java + Ada dispatching Robert I. Eachus
1996-11-05  0:00           ` Joachim Durchholz
1996-11-06  0:00           ` Robert I. Eachus
1996-11-08  0:00             ` Don Harrison
1996-11-08  0:00               ` Jon S Anthony
1996-11-08  0:00               ` Robert A Duff
1996-11-12  0:00                 ` Don Harrison
1996-11-12  0:00                   ` Robert A Duff
1996-11-13  0:00                     ` Don Harrison
1996-11-13  0:00                       ` Robert A Duff
1996-11-14  0:00                         ` Don Harrison
1996-11-13  0:00                       ` Jon S Anthony
1996-11-15  0:00                         ` Don Harrison
1996-11-19  0:00                           ` Jon S Anthony
1996-11-20  0:00                             ` Don Harrison
1996-11-12  0:00                   ` Joachim Durchholz
1996-11-15  0:00                     ` Richard Riehle
1996-11-16  0:00                     ` Interfacing contracts (Was: Eiffel and Java + Ada dispatching) Geert Bosch
1996-11-17  0:00                       ` Robert A Duff
1996-11-14  0:00               ` Eiffel and Java + Ada dispatching Robert I. Eachus
1996-11-14  0:00                 ` Robert A Duff
1996-11-15  0:00                 ` Don Harrison
1996-11-15  0:00                   ` Robert I. Eachus
1996-11-19  0:00                     ` Don Harrison
1996-11-18  0:00                       ` Vincent Celier
1996-11-22  0:00                         ` Don Harrison
1996-11-19  0:00                 ` Jon S Anthony
1996-11-15  0:00               ` portmanteau (was Re: Eiffel and Java + Ada dispatching) Robert I. Eachus
1996-11-07  0:00           ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-07  0:00           ` Robb Nebbe
1996-11-12  0:00           ` Jon S Anthony
1996-10-31  0:00   ` Joachim Durchholz
1996-11-01  0:00   ` Eiffel and Java Matthias Ernst
1996-11-01  0:00     ` Benedict A. Gomes
1996-11-01  0:00     ` William Clodius
1996-11-02  0:00   ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-02  0:00   ` Jon S Anthony
1996-11-04  0:00   ` Eiffel and Java Robert I. Eachus
1996-10-30  0:00 ` Jon S Anthony
1996-11-01  0:00   ` Don Harrison
1996-11-01  0:00     ` Jon S Anthony
1996-11-07  0:00       ` Marcos F. F. de Macedo
1996-11-11  0:00         ` Ian Joyner
1996-11-12  0:00         ` Don Harrison
1996-11-13  0:00           ` Norman H. Cohen
1996-11-15  0:00             ` Don Harrison
1996-11-14  0:00           ` Jon S Anthony
1996-11-15  0:00             ` Don Harrison
1996-11-19  0:00               ` Jon S Anthony
1996-11-21  0:00                 ` Don Harrison
1996-11-12  0:00     ` Jon S Anthony
1996-10-31  0:00 ` Joachim Durchholz
1996-11-01  0:00 ` Jon S Anthony
1996-11-02  0:00 ` Jon S Anthony
1996-11-03  0:00 ` Eiffel and Java + Ada dispatching Joachim Durchholz
1996-11-04  0:00 ` Eiffel and Java Richard A. O'Keefe
  -- strict thread matches above, loose matches on Subject: below --
1996-10-28  0:00 cosc19z5@bayou.uh.edu
     [not found] ` <01bbc7f6$b1c0b7a0$LocalHost@gaijin>
1996-11-01  0:00   ` Ranjan Bagchi
1996-11-01  0:00   ` Alan Lovejoy
1996-11-01  0:00     ` Chris
1996-11-02  0:00 Ell
1996-11-02  0:00 ` traymond
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox