From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: On pragma Precondition and types
Date: Thu, 2 Oct 2008 18:09:57 -0500
Date: 2008-10-02T18:09:57-05:00 [thread overview]
Message-ID: <gc3kt0$pf$1@jacob-sparre.dk> (raw)
In-Reply-To: 48e4dc3b$0$6604$9b4e6d93@newsspool3.arcor-online.net
"Georg Bauhaus" <rm.dash-bauhaus@futureapps.de> wrote in message
news:48e4dc3b$0$6604$9b4e6d93@newsspool3.arcor-online.net...
...
> I want to add a precondition of P. The precondition
> involves F,
>
> procedure P (X: in out T);
> pragma Precondition (F(X));
>
> function F (X: T) return Boolean;
>
>
> But when the compiler sees the pragma Precondition,
> it has not yet seen F. Therefore, by the principle
> of linear reading, the precondition cannot be compiled,
> IIUC.
You declare F first, of course. It's precondition (if any) can't depend on
P, so there is no ordering problem. (And the order of the bodies is not
constrained by the order of the specs.)
I suppose you could claim that F is only intended to be used in
Preconditions and thus should be hidden somehow. But I find that dubious -
how is the programmer going to avoid triggering the precondition if they
can't call F to check?
For instance, in Claw, one could imagine F = Is_Valid and P = Move. It's not
at all unusual to see code like:
if Is_Valid (Some_Window) then
Move (Some_Window, ...);
end if;
Of course, if you can guarentee the precondition some other way, that's
preferred. But it's unlikely to be the general case.
Similarly, hiding the routines in the precondition is likely to make it
harder to understand. And a contract that is hard to understand does no one
any favors.
So, I don't think that there will be much interest in this idea. (Not to
mention the shreek that Adam mentioned...)
Randy.
next prev parent reply other threads:[~2008-10-02 23:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-02 14:35 On pragma Precondition and types Georg Bauhaus
2008-10-02 15:02 ` Adam Beneschan
2008-10-02 23:09 ` Randy Brukardt
2008-10-02 23:09 ` Randy Brukardt [this message]
2008-10-02 23:09 ` Randy Brukardt
2008-10-03 8:59 ` Dmitry A. Kazakov
2008-10-03 9:35 ` Georg Bauhaus
2008-10-03 10:50 ` Dmitry A. Kazakov
2008-10-03 12:41 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox