comp.lang.ada
 help / color / mirror / Atom feed
From: geert@fozzie.sun3.iaf.nl (Geert Bosch)
Subject: Interfacing contracts (Was: Eiffel and Java + Ada dispatching)
Date: 1996/11/16
Date: 1996-11-16T00:00:00+00:00	[thread overview]
Message-ID: <56kgrf$61t@fozzie.sun3.iaf.nl> (raw)
In-Reply-To: 6KkYnJwk3RB@herold.franken.de


Joachim Durchholz (jhd@herold.franken.de) wrote:
  "This is the normal contract on parameter and result types. Eiffel  
   contracts also include arbitrary boolean expressions, extending the  
   contracting idea far into the area of program semantics.
   Just as a parameter type makes clear what sorts of parameters are  
   required, the preconditions make clear under what circumstances the  
   routine may be called and expected to return a correct result. The Eiffel  
   postconditions list what the routine guarantees to the caller in turn."

Although Ada's interface capabilities are good enough to define the
range of results, these extra capabilities of Eiffel are very useful indeed. 
Especially for the large programs that are built using Ada. 

Something I'd really like to have is an Ada extension for specifying
both interface constraints and implementation conditions. 

Example for interface specification that might be accepted by
an Ada implementation without violating the Ada-95 standard (yes?):

   --  Integer square root function truncating the exact result
   function Square_Root (I : Natural) return Natural;

   for Square_Root'Post_Condition use
      Square_Root (I)  ** 2 <= I and (Square_Root (I) + 1) ** 2 > I;

In implementation:
   function Square_Root (I : Natural) return Natural is
      Lowerbound : Natural := Natural'Min (2, I);
      for Lowerbound'Invariant use Lowerbound ** 2 <= I;
      ...
   begin
      ...
   end Square_Root;

The advantage of checkng the pre- and post-conditions is that
the user of the subprogram or primitive has a better specification
of what the function (or procedure or...) does. The advantage of
a machine checkable specification is that the user can rely on them.
Ordinary comments on the other hand are often out of date.

Also when my algorithm using the Square_Root function specified
above doesn't work correctly, I only have to look at the specification
to know that the error won't be in the Square_Root implementation.
This is much better than to try figuring out whether the Code is correct
or not. Using a pragma Assert on the computed value just before return
has some drawbacks: you have to look at the implementation to know whether
these assertions are present, and you have to make sure that all possible
returns from the function are checked.

Another point is that it is possible in many cases to automatically
prove invariants. When the proving software cannot prove invariants,
the programmer can (and maybe should) make smaller steps that are
easier to prove. When all invariants can be proved, no checks are
necessary so speed is the same.

Actually it might be possible for the compiler to take advantage of
invariants and pre- / post-conditions by both eliminating checks and
taking advantage of the extra information.
    
Note that in the examples above, the formal parameters are visible
in the expression and that the expression is in fact a function.

Regards,
   Geert
-- 
E-Mail: geert@sun3.iaf.nl    




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

Thread overview: 162+ 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
1996-10-30  0:00   ` 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-30  0:00   ` Jon S Anthony
1996-11-01  0:00     ` Eiffel and Java + Ada dispatching Jean-Marc Jezequel
1996-10-31  0:00   ` Eiffel and Java Joachim Durchholz
1996-11-01  0:00   ` Norman H. Cohen
1996-11-02  0:00   ` Jon S Anthony
1996-11-02  0:00   ` Eiffel and Java + Ada dispatching Jon S Anthony
1996-11-03  0:00   ` Eiffel and Java 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   ` Eiffel and Java + Ada dispatching Vincent WEBER
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     ` Don Harrison
1996-10-30  0:00       ` Jon S Anthony
1996-10-29  0:00   ` Eiffel and Java 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-30  0:00   ` David Petrie Stoutamire
1996-10-30  0:00   ` Eiffel and Java + Ada dispatching 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   ` Robert I. Eachus
1996-10-31  0:00   ` Joachim Durchholz
1996-10-31  0:00   ` Jon S Anthony
     [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           ` Joachim Durchholz
1996-11-05  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                   ` Jon S Anthony
1996-11-11  0:00                     ` Don Harrison
1996-11-07  0:00                   ` Jon S Anthony
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-08  0:00                   ` bill.williams
1996-11-11  0:00                     ` Don Harrison
1996-11-06  0:00             ` Eiffel and Java + Ada dispatching Jean-Marc Jezequel
1996-11-07  0:00               ` Robb Nebbe
1996-11-08  0:00             ` Robert I. Eachus
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                   ` Joachim Durchholz
1996-11-15  0:00                     ` Richard Riehle
1996-11-16  0:00                     ` Geert Bosch [this message]
1996-11-17  0:00                       ` Interfacing contracts (Was: Eiffel and Java + Ada dispatching) Robert A Duff
1996-11-12  0:00                   ` Eiffel and Java + Ada dispatching 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-14  0:00               ` 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 Robb Nebbe
1996-11-07  0:00           ` Jon S Anthony
1996-11-12  0:00           ` Jon S Anthony
1996-11-01  0:00     ` Jean-Marc Jezequel
1996-11-01  0:00   ` Eiffel and Java Matthias Ernst
1996-11-01  0:00     ` William Clodius
1996-11-01  0:00     ` Benedict A. Gomes
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
replies disabled

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