comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: GNAT packages in Linux distributions
Date: Sat, 15 May 2010 11:30:27 +0200
Date: 2010-05-15T11:30:27+02:00	[thread overview]
Message-ID: <1ru2ex5e8d8y6$.jjts04h6mhb.dlg@40tude.net> (raw)
In-Reply-To: 4bede0af$0$6883$9b4e6d93@newsspool2.arcor-online.net

On Sat, 15 May 2010 01:45:50 +0200, Georg Bauhaus wrote:

> On 5/13/10 10:39 AM, Dmitry A. Kazakov wrote:
> 
>>>     Ada seems better here.  But before the arrival of preconditions
>>> etc. Ada didn't have that much to offer to programmers wanting
>>> to state sets of permissible values, for example for subprogram
>>> parameters.
>>
>> Ada has strong types. "A set of permissible values" does not look like
>> that.
> 
> Ada's strong types are not really strong enough to express
> a supplier library's ADT expectations in the sense of DbC.

No type system can express the program semantics. Otherwise you would need
not program any bodies, only declarations.

> Again, can you produce a statically checked invariant for
> subtype Even?

Yes, I can:

   type Even is private; -- No literals visible
   function To_Integer (X : Even) return Integer;
   function To_Even (X : Integer) return Even;
private
   type Even is new Integer;  -- Use literals as follows: 1 means 2

   function To_Integer (X : Even) return Integer is
   begin
      return Integer (X * 2);
   end To_Integer;

   function To_Even (X : Integer) return Even is
   begin
      if X mod 2 = 0 then
         return Even (X / 2);
      else
         raise Constraint_Error;
      end if;
   end To_Even;

>>> package P is
>>>
>>>     type Number is range 1 .. 10;
>>>     function Compute (A, B: Number) return Number
>>>       with Precondition =>  A>= B;
>>
>> I don't understand this notation.
> 
> It says that the client of Compute would have to provide
> A, B such that A >= B if client expects Compute to produce
> its postcondition; otherwise,

Compute should have the contract: if the sequence A,B is sorted then ...
else Constraint_Error propagated. And of course, A, B is just an interval
[B, A], and should be declared as such:

   function Compute (X : Interval) return Number
      with Precondition => True;

> Yes. Only, a DbC system can be quite helpful in checking
> my understanding of more formal "comments".

You say that Eiffel DbC is about writing structured comments? I do not
object.

>> Note, since your "preconditions" are not static,
>> how can you know *what* they say, in order to do as they do?
> 
> I can write my client code such that the preconditions are
> true.

Really? What about:

pre : not HALT(p)

There is a reason why they aren't static.

>>> IOW, no redundant checks.
>>
>> No, it would be *inconsistent* checks. No program can check itself.
> 
> DbC checks are not part of the (intended) program.  Monitoring can be
> turned off and this should have no effect on program correctness.

and thus on program execution. q.e.d.

>> Trivially:
>>
>>     function Careful (S: String_80; X: Index_80)
>>        with Precondition True;
>>        with Postcondition<whatever>  or Constraint_Error
> 
> This is legitimate I'd say, but is also is a destructive omission of
> what the precondition above does specify.  Yours (True) does not tell
> the client programmer the conditions that by DbC will guarantee
> Postcondition.  Without hardware failure or other occurrences
> that cannot be expected to be handled by the Careful algorithm,
> Careful must produce Postcondition provided odd Index_80 numbers
> are passed for X.  But in your version,
> 
> (a) there is nothing the programmer knows about valid Index_80
> values (viz. the odd ones)

They are *all* valid, that is the contract of Careful.

> (b) there is no debugging hook that can be turned on
> or off (monitoring the precondition X rem 2 = 1).

Debugging hooks do not belong to code.

>> other things you mentioned are control flow control statements. It is
>> really simply: an error/correctness check is a statement about the program
>> behavior. If-statement/exception etc is the program behavior.
> 
> Normal If-statements and exceptions cannot be turned off.

Come on. C has preprocessor!

>> Note
>> that your "DbC mindset" includes the programmer(s) into the system,
>> delivered and deployed. Isn't that indicatory? (:-))
> 
> The programmer is the one ingredient that matters most in DbC,
> since programming is a human activity, and contracts are between
> clients and suppliers of software components (classes).

That is what your car manufacturer will tell you next time, when the brake
system will accelerate instead of braking...

>> And how do you rescue from:
>>
>>     function "-" (X : Positive) return Positive;
>>
>> Note, if you handle an exception then it is same as if-statement. (I agree
>> that if-statements could be better arranged, have nicer syntax etc. Is that
>> the essence of Eiffel's DbC?)
> 
> I'm assuming this is not an input-sanitizing function.

It was unary minus.

> Where Ada requires "ifs" for bounds checking and raising an
> exception accordingly, DbC/Eiffel requires that you express the
> correctness properties of subprograms *and* that you choose
> whether or not you want the "if", and which ones.

Bounds are one kind of constraints. Eiffel has more of those. Ada goes in
the same direction as Robert's response shows. I don't like it for two
reasons:

1. Dynamic checks. This was discussed. Correctness checks shall be static,
else it is a part of the behavior to be contracted as any other.

2. It is weakly/un-typed. The constraints you impose on input and output
are specifications of a [sub]type.

2.a. This type is anonymous
2.b. This type mutates (precondition /= postcondition)
2.c. This type is inferred and structurally equivalent

To me this is a deep breach with the core of Ada type system.

> This specifies that assigning -1 to a positive will raise an exception.
> It does not specify the possible values for Even (which would be
> constrained to include only even numbers).

You have to define "possible value":

1. Member of the type domain set. (3 is a member of the Even as a subtype
of Integer)
2. Value of an initialized instance (3 cannot be a value of any Even
object)

(Considering Even an Ada subtype or a type inheriting to integer.)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-05-15  9:30 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-09 17:40 GNAT packages in Linux distributions Dmitry A. Kazakov
2010-05-09 18:16 ` Ludovic Brenta
2010-05-09 19:36   ` Dmitry A. Kazakov
2010-05-09 21:26     ` Ludovic Brenta
2010-05-09 21:34       ` Yannick Duchêne (Hibou57)
2010-05-10  1:20         ` Ludovic Brenta
2010-05-10  1:26           ` Ludovic Brenta
2010-05-25 20:40             ` Yannick Duchêne (Hibou57)
2010-05-10  9:41         ` Stephen Leake
2010-05-10  9:46           ` Ludovic Brenta
2010-05-10 14:29             ` sjw
2010-05-11  7:51               ` Ludovic Brenta
2010-05-11  9:33                 ` sjw
2010-05-10 18:47           ` Yannick Duchêne (Hibou57)
2010-05-09 21:28     ` Yannick Duchêne (Hibou57)
2010-05-09 21:30       ` Yannick Duchêne (Hibou57)
2010-05-09 22:44       ` Simon Wright
2010-05-10  7:54         ` Dmitry A. Kazakov
2010-05-10  8:02       ` Dmitry A. Kazakov
2010-05-10 18:45         ` Yannick Duchêne (Hibou57)
2010-05-10 21:00           ` Ludovic Brenta
2010-05-10 22:17             ` Yannick Duchêne (Hibou57)
2010-05-11  6:56               ` Ludovic Brenta
2010-05-11  7:39           ` Dmitry A. Kazakov
2010-05-11  8:06             ` Yannick Duchêne (Hibou57)
2010-05-11 15:46             ` Pascal Obry
2010-05-11 16:05               ` Yannick Duchêne (Hibou57)
2010-05-11 16:09                 ` Pascal Obry
2010-05-11 16:09                   ` Pascal Obry
2010-05-11 17:08                     ` stefan-lucks
2010-05-11 16:39                       ` Yannick Duchêne (Hibou57)
2010-05-11 19:45                         ` Yannick Duchêne (Hibou57)
2010-05-11 23:44                           ` Yannick Duchêne (Hibou57)
2010-05-12 12:12                             ` Mark Lorenzen
2010-05-12 14:55                               ` Yannick Duchêne (Hibou57)
2010-05-11 17:35                       ` Pascal Obry
2010-05-11 18:06                         ` Yannick Duchêne (Hibou57)
2010-05-11 16:23                   ` Yannick Duchêne (Hibou57)
2010-05-11 16:41                     ` J-P. Rosen
2010-05-11 16:45                 ` Dmitry A. Kazakov
2010-05-11 19:21                   ` Yannick Duchêne (Hibou57)
2010-05-12  8:41                   ` stefan-lucks
2010-05-12 14:52                     ` Yannick Duchêne (Hibou57)
2010-05-12 15:59                       ` Phil Thornley
2010-05-12 16:49                         ` Yannick Duchêne (Hibou57)
2010-05-13  8:05                           ` Phil Thornley
2010-05-12 15:37                     ` Dmitry A. Kazakov
2010-05-12 16:06                       ` Yannick Duchêne (Hibou57)
2010-05-12 17:24                         ` Dmitry A. Kazakov
2010-05-12 18:09                           ` Georg Bauhaus
2010-05-12 18:33                             ` Dmitry A. Kazakov
2010-05-12 18:53                               ` Georg Bauhaus
2010-05-12 21:57                                 ` Dmitry A. Kazakov
2010-05-13  2:03                                   ` Georg Bauhaus
2010-05-13  8:39                                     ` Dmitry A. Kazakov
2010-05-14 23:45                                       ` Georg Bauhaus
2010-05-15  9:30                                         ` Dmitry A. Kazakov [this message]
2010-05-15 18:39                                           ` Georg Bauhaus
2010-05-15 20:33                                             ` Dmitry A. Kazakov
2010-05-15  0:17                             ` Robert A Duff
2010-05-15  9:40                               ` Dmitry A. Kazakov
2010-05-12 18:15                           ` Georg Bauhaus
2010-05-25 20:45                           ` Yannick Duchêne (Hibou57)
2010-05-26  7:55                             ` Dmitry A. Kazakov
2010-05-26  8:38                             ` stefan-lucks
2010-05-26  8:01                               ` Yannick Duchêne (Hibou57)
2010-05-26 11:25                               ` Yannick Duchêne (Hibou57)
2010-05-26 13:02                                 ` stefan-lucks
2010-05-26 12:22                                   ` Yannick Duchêne (Hibou57)
2010-05-27 12:47                                     ` stefan-lucks
2010-05-27 12:26                                       ` Yannick Duchêne (Hibou57)
2010-05-26 13:06                                   ` (see below)
2010-05-27 12:41                                     ` stefan-lucks
2010-05-27 12:29                                       ` Yannick Duchêne (Hibou57)
2010-05-27 15:21                                       ` (see below)
2010-06-03  3:16                                         ` Yannick Duchêne (Hibou57)
2010-06-03 10:42                                           ` Brian Drummond
2010-06-03 21:14                                             ` (see below)
2010-06-03 22:00                                               ` Britt Snodgrass
2010-06-03 22:29                                                 ` (see below)
2010-06-03 13:49                                           ` (see below)
2010-06-04 13:49                                             ` Georg Bauhaus
2010-06-04 13:53                                               ` Georg Bauhaus
2010-06-04 14:24                                               ` Yannick Duchêne (Hibou57)
2010-06-04 17:34                                                 ` Georg Bauhaus
2010-06-04 15:29                                               ` (see below)
2010-05-12 18:10                       ` stefan-lucks
2010-05-12 17:48                         ` Dmitry A. Kazakov
2010-05-13  0:37                           ` stefan-lucks
2010-05-13  9:09                             ` Dmitry A. Kazakov
2010-05-13  0:33                     ` Yannick Duchêne (Hibou57)
2010-05-10 14:15       ` GNAT Pro license (was: " Peter Hermann
2010-05-10  1:40 ` Björn Persson
2010-05-10  2:04   ` Yannick Duchêne (Hibou57)
2010-05-10  7:01     ` Ludovic Brenta
replies disabled

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