comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada2012 : When to use expression functions rather than function bodies?
Date: Sat, 17 Dec 2011 14:11:35 +0100
Date: 2011-12-17T14:11:35+01:00	[thread overview]
Message-ID: <1xbajufyxdf4j.1moa6g6ouhykk$.dlg@40tude.net> (raw)
In-Reply-To: 1697334721345818104.523316rmhost.bauhaus-maps.arcor.de@news.arcor.de

On 17 Dec 2011 12:45:38 GMT, georg bauhaus wrote:

> "Randy Brukardt" <randy@rrsoftware.com> wrote:
>> 
>> You could write all of your preconditions like:
>> 
>>      procedure Do_It (A, B : in out Integer)
>>          with Pre => Do_It_Precondition (A, B);
>> 
>> but no one would have any idea what the precondition is. 
> 
> I'm guessing that Dmitry will suggest
> 
>   Procedure Do_It (A, B: Int_Sats_Pre) with
>     Pre => True;
> 
> will be safer and will convey the idea
> of the precondition better: it is in the type system.

Not really. The key question is whether Do_It_Precondition is statically
checkable. Note also that it is not always possible to break a [true]
precondition into a set of *independent* subtype constraints. As an example
consider:

   function "+" (Left, Right : Dimensioned) return Dimensioned;

The precondition here (IFF measurement units have to be checked statically)
is that Left and Right have the same unit.

If the measurement units cannot be checked statically THEN the precondition
is "true" and the contract of "+" includes Unit_Error.

Argument against Do_It_Precondition is same as against a formula:
declarations should include minimum executable code. The language of
declarations (types algebra operations) must be clearly, visibly separated
from the object (executable) language. All cases when executable code slips
into the declarations cause difficulties because of the contexts mismatch,
e.g.

   procedure Foo (Default : Integer := Get);
       -- What is the default here? When the default is read from standard
       -- input?

Pure and static expressions are OK because the context is irrelevant.

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



  reply	other threads:[~2011-12-17 13:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 12:25 Ada2012 : When to use expression functions rather than function bodies? Martin
2011-12-16 13:24 ` Dmitry A. Kazakov
2011-12-17  1:03   ` Randy Brukardt
2011-12-16 18:03 ` Adam Beneschan
2011-12-16 20:36   ` Martin Dowie
2011-12-16 21:34     ` Adam Beneschan
2011-12-16 23:08       ` Adam Beneschan
2011-12-17 12:26   ` georg bauhaus
2011-12-16 22:01 ` Jeffrey Carter
2011-12-16 22:52   ` Adam Beneschan
2011-12-16 23:09     ` Adam Beneschan
2011-12-17  1:21     ` Randy Brukardt
2011-12-17 12:45       ` georg bauhaus
2011-12-17 13:11         ` Dmitry A. Kazakov [this message]
2011-12-19 23:34           ` Randy Brukardt
replies disabled

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