comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Overriding puzzle
Date: Sun, 3 Jan 2016 01:18:16 -0600
Date: 2016-01-03T01:18:16-06:00	[thread overview]
Message-ID: <n6ahvo$7b3$1@loke.gir.dk> (raw)
In-Reply-To: dek6taF5o9dU1@mid.individual.net

"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message 
news:dek6taF5o9dU1@mid.individual.net...
> On 15-12-31 01:10 , Randy Brukardt wrote:
...
>> The model of Ada is that within a routine (including inherited routines) 
>> the
>> object acts as if it had the named type. This makes it much easier to 
>> reason
>> about the routine, as the behavior of all of the routines called is 
>> known.
>>
>> When you redispatch, you no longer can reason in any useful way about the
>> behavior of the call -- essentially you are depending on "magic" (and the
>> competency of others) to get the right answer. In limited circumstances
>> (like the OP), it works well, but for general programming, look out!
>
> The same (IMO a bit paranoid) argument would logically apply to all 
> dispatching calls, including dispatching calls from class-wide 
> subprograms.

It does. The problem is that Ada contracts aren't strong enough to describe 
LSP, so clueless (or hasty) programmers can easily write code that violates 
it.

But let me back up a bit. Overloading has a similar problem, but that 
doesn't necessarily mean one has to avoid overloading. Nor do you have to 
avoid dispatching -- it just needs to be used judiciously.

In the specific case of a class-wide subprogram (really a subprogram with 
class-wide parameters), the problem is more obvious (and less dangerous). 
You obviously can't reason about a call based on a specific type, so no one 
will try to do that.

> The conclusion would be that one cannot reason in any useful way about any 
> dispatching call. I don't agree with that conclusion.

Well, you could reason about a call based on LSP, but nothing in Ada forces 
the bodies to follow LSP, so in that case you're just hoping that everyone 
did the right thing. (And since people can extend in the future, you are 
hoping that someone years from now does the right thing -- good luck with 
that.) [Pre'Class helps a bit, but of course there is a lot that can't be 
described that way.]

It's obviously harsh to say that you can't reason about a call, it's more 
that you are making a lot of assumptions in that case that don't necessarily 
hold. So you're on thinner ice that you typically realize.

                          Randy.




  parent reply	other threads:[~2016-01-03  7:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-30 14:49 Overriding puzzle gautier_niouzes
2015-12-30 15:10 ` Egil H H
2015-12-30 17:31   ` gautier_niouzes
2015-12-30 18:07   ` marciant
2015-12-30 18:24     ` gautier_niouzes
2015-12-30 21:40       ` marciant
2015-12-30 23:10         ` Randy Brukardt
2015-12-31  8:22           ` Niklas Holsti
2015-12-31  8:42             ` Dmitry A. Kazakov
2016-01-03  7:18             ` Randy Brukardt [this message]
2015-12-31 16:30           ` marciant
2015-12-30 23:13     ` 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