comp.lang.ada
 help / color / mirror / Atom feed
* On pragma Precondition and types
@ 2008-10-02 14:35 Georg Bauhaus
  2008-10-02 15:02 ` Adam Beneschan
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Georg Bauhaus @ 2008-10-02 14:35 UTC (permalink / raw)


Suppose there is a type T with operations P and F,

   type T is private;

   procedure P (X: in out T);
   function  F (X: T) return Boolean;


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.

Could there be a rule for pragmas, say, allowing forward
references? Or can these rules be tied to some suitable
constraint syntax?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Adam Beneschan @ 2008-10-02 15:02 UTC (permalink / raw)


On Oct 2, 7:35 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:
> Suppose there is a type T with operations P and F,
>
>    type T is private;
>
>    procedure P (X: in out T);
>    function  F (X: T) return Boolean;
>
> 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.
>
> Could there be a rule for pragmas, say, allowing forward
> references?

If you just heard a strange high-pitched noise, it was the sound of
several dozen compiler maintainers reacting to your proposal in
terror.  Sort of the same sound Janet Leigh made in "Psycho"........

                                 -- Adam



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  2008-10-02 14:35 On pragma Precondition and types Georg Bauhaus
                   ` (2 preceding siblings ...)
  2008-10-02 23:09 ` Randy Brukardt
@ 2008-10-02 23:09 ` Randy Brukardt
  3 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2008-10-02 23:09 UTC (permalink / raw)


"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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  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
  2008-10-02 23:09 ` Randy Brukardt
  3 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2008-10-02 23:09 UTC (permalink / raw)


"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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  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
  2008-10-03  8:59   ` Dmitry A. Kazakov
  2008-10-02 23:09 ` Randy Brukardt
  3 siblings, 1 reply; 9+ messages in thread
From: Randy Brukardt @ 2008-10-02 23:09 UTC (permalink / raw)


"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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  2008-10-02 23:09 ` Randy Brukardt
@ 2008-10-03  8:59   ` Dmitry A. Kazakov
  2008-10-03  9:35     ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry A. Kazakov @ 2008-10-03  8:59 UTC (permalink / raw)


On Thu, 2 Oct 2008 18:09:57 -0500, Randy Brukardt wrote:

> 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?

There is more in that. Preconditions semantically do not belong to the
program. Thus it makes a lot of sense to have F declared and implemented
outside it. If programs could be written in 3D space, the declaration of F
should be written orthogonal to other text... (:-))

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  2008-10-03  8:59   ` Dmitry A. Kazakov
@ 2008-10-03  9:35     ` Georg Bauhaus
  2008-10-03 10:50       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2008-10-03  9:35 UTC (permalink / raw)


Dmitry A. Kazakov wrote:
> On Thu, 2 Oct 2008 18:09:57 -0500, Randy Brukardt wrote:
> 
>> 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?
> 
> There is more in that. Preconditions semantically do not belong to the
> program.

I guess that Assertion_Policy helps restoring the bug-free,
assertion-less, genuine, trouble-free, original program.

IMHO, preconditions belong to any program that is honest
about real-life programming practices. ("Our programs do
include checks affecting its operation just like anything
in it.")



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  2008-10-03  9:35     ` Georg Bauhaus
@ 2008-10-03 10:50       ` Dmitry A. Kazakov
  2008-10-03 12:41         ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry A. Kazakov @ 2008-10-03 10:50 UTC (permalink / raw)


On Fri, 03 Oct 2008 11:35:45 +0200, Georg Bauhaus wrote:

> IMHO, preconditions belong to any program that is honest
> about real-life programming practices.

likewise the color of paper it is printed on...

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: On pragma Precondition and types
  2008-10-03 10:50       ` Dmitry A. Kazakov
@ 2008-10-03 12:41         ` Georg Bauhaus
  0 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2008-10-03 12:41 UTC (permalink / raw)


Dmitry A. Kazakov wrote:
> On Fri, 03 Oct 2008 11:35:45 +0200, Georg Bauhaus wrote:
> 
>> IMHO, preconditions belong to any program that is honest
>> about real-life programming practices.
> 
> likewise the color of paper it is printed on...

Right, black ink does not work well on black paper.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-10-03 12:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
2008-10-02 23:09 ` Randy Brukardt

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