From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Interfaces and the Liskov Substitution Principle
Date: Thu, 24 May 2007 15:42:36 +0200
Date: 2007-05-24T15:40:29+02:00 [thread overview]
Message-ID: <zjf5zns614ns$.1p1ti5rj3rim7.dlg@40tude.net> (raw)
In-Reply-To: 1180011507.159515.46920@o5g2000hsb.googlegroups.com
On 24 May 2007 05:58:27 -0700, Maciej Sobczak wrote:
> On 24 Maj, 10:02, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>
>>> Can it be dispatching on both arguments?
>>
>> It shall be. It is a pity that Ada does not have MD.
>
> Yes, but that would not automatically solve the problem, see below.
>
>>> Coming from C++, I have never seen any single example where assignment
>>> made sense with polymorphic hierarchies.
>>
>> Real-life example. Consider a threaded library. Let you have an Ada-like
>> rendezvous. You wanted to propagate an exception raised in the callee to
>> the caller. Similarly, let an exception is propagated out of a child
>> thread. You want to continue its propagation to the parent.
>>
>>> Do you know any such example? Can you show it?
>>
>> Marshaling objects.
>
> No, I'm not convinced. This is more like cloning.
>
> Assignment of class-wide type is strange/dangerous, beucause it might
> require dynamic change of the object's type.
No it cannot, because otherwise it weren't dispatching in the left
argument. But you have explained it later on.
> Assigning Circle to Triangle (through Object'Class) cannot reasonably
> work with preserving the types of each object. The Triangle would need
> to become Circle - and this action might change the ability of the
> object to respond to messages that are supposedly in its interface. Or
> change the invariants in the original type.
>
> declare
> C : Circle;
> T : Triangle;
> begin
> Do_Something(C, T); -- T := C; inside
> -- and here some code still thinks that T is a Triangle,
> -- which according to its declaration in the same scope
> -- must be true (but isn't!)
> end;
>
> There is no way to change the type of T in the code above and without
> it there is no way to execute the assignment.
No, you presume some meaning in the name ":=", but there is no one. It just
is an operation to call as any other. Whatever Circle := Triangle might
mean, is up to the designer of this types hierarchy.
> You can restrict the operation so that the arguments must have the
> same tag (and then MD is not needed anymore), but such restriction can
> be run-time only and cannot be expressed in the signature of
> Do_Something.
>
> Your marshalling example is interesting, but actually works
> differently: you don't have the left-hand object before assignment;
> you just make a copy of something and give the copy some identity.
> It's just a copy-construction basically, or cloning (if polimorphic).
> You can do this either with access variables or with initialization of
> class wide type (which is *not* an assignment).
>
> I was talking about real assignment - and this assumes that two
> objects already exist and we make one to be equal to the other. There
> is no way to do it right.
OK, for this the use case is [semi-]"equivalent" types hierarchies. They
often appear when you have concurrent representations of the same thing.
Typical example (poorly designed in Ada) is:
String, UTF8_String, Wide_String, Wide_Wide_String, Unbounded_String,
Unbounded_UTF8_String ...
Surely you wanted to cross-assign each other of them.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2007-05-24 13:42 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-23 19:47 Ada Interfaces and the Liskov Substitution Principle Stefan Lucks
2007-05-23 20:32 ` Ludovic Brenta
2007-05-23 22:00 ` Randy Brukardt
2007-05-24 0:56 ` Anh Vo
2007-05-24 18:27 ` Pascal Obry
2007-05-24 18:39 ` Dmitry A. Kazakov
2007-05-24 18:51 ` Pascal Obry
2007-05-24 22:44 ` Randy Brukardt
2007-05-24 6:57 ` Stefan Lucks
2007-05-23 20:54 ` Maciej Sobczak
2007-05-23 21:58 ` Randy Brukardt
2007-05-24 7:29 ` Maciej Sobczak
2007-05-24 8:02 ` Dmitry A. Kazakov
2007-05-24 12:58 ` Maciej Sobczak
2007-05-24 13:42 ` Dmitry A. Kazakov [this message]
2007-05-24 22:08 ` Robert A Duff
2007-07-01 1:00 ` David Thompson
2007-05-24 22:58 ` Randy Brukardt
2007-05-25 7:52 ` Maciej Sobczak
2007-05-25 8:21 ` Dmitry A. Kazakov
2007-05-25 20:27 ` Maciej Sobczak
2007-05-26 7:48 ` Dmitry A. Kazakov
2007-05-27 8:30 ` Maciej Sobczak
2007-05-27 10:04 ` Dmitry A. Kazakov
2007-05-29 8:03 ` Maciej Sobczak
2007-05-29 13:18 ` Dmitry A. Kazakov
2007-05-29 13:32 ` Dmitry A. Kazakov
2007-05-29 15:34 ` Maciej Sobczak
2007-05-29 17:07 ` Dmitry A. Kazakov
2007-05-30 7:40 ` Maciej Sobczak
2007-05-30 8:43 ` Dmitry A. Kazakov
2007-05-30 12:54 ` Maciej Sobczak
2007-05-30 13:56 ` Dmitry A. Kazakov
2007-05-30 16:49 ` vgodunko
2007-05-30 20:52 ` Maciej Sobczak
2007-05-31 8:15 ` Dmitry A. Kazakov
2007-05-31 13:46 ` Maciej Sobczak
2007-06-01 7:29 ` Dmitry A. Kazakov
2007-06-01 13:32 ` Maciej Sobczak
2007-06-01 14:53 ` Dmitry A. Kazakov
2007-06-01 20:31 ` Maciej Sobczak
2007-06-02 8:19 ` Dmitry A. Kazakov
2007-06-02 16:49 ` Maciej Sobczak
2007-06-03 7:09 ` Dmitry A. Kazakov
2007-06-03 22:04 ` Maciej Sobczak
2007-06-04 8:08 ` Dmitry A. Kazakov
2007-06-04 17:02 ` Maciej Sobczak
2007-06-05 8:35 ` Dmitry A. Kazakov
2007-06-05 22:12 ` Maciej Sobczak
2007-06-06 8:21 ` Dmitry A. Kazakov
2007-06-06 14:46 ` Maciej Sobczak
2007-06-06 15:11 ` Maciej Sobczak
2007-06-06 15:32 ` Markus E Leypold
2007-05-24 10:42 ` Georg Bauhaus
2007-05-24 13:41 ` Dmitry A. Kazakov
2007-05-25 16:59 ` Markus E Leypold
2007-05-28 9:52 ` Georg Bauhaus
2007-05-28 11:50 ` Dmitry A. Kazakov
2007-05-28 23:32 ` Georg Bauhaus
2007-05-29 12:05 ` Dmitry A. Kazakov
2007-05-29 13:33 ` Georg Bauhaus
2007-05-29 17:29 ` Dmitry A. Kazakov
2007-05-29 20:46 ` Georg Bauhaus
2007-05-30 7:53 ` Dmitry A. Kazakov
2007-05-30 13:18 ` Georg Bauhaus
2007-05-31 10:27 ` Dmitry A. Kazakov
2007-05-31 11:44 ` Georg Bauhaus
2007-06-01 7:37 ` Dmitry A. Kazakov
2007-06-01 10:07 ` Markus E Leypold
2007-06-01 11:41 ` Georg Bauhaus
2007-06-01 13:07 ` Dmitry A. Kazakov
2007-05-28 13:47 ` Markus E Leypold
2007-05-28 23:12 ` Georg Bauhaus
2007-05-28 13:56 ` Markus E Leypold
2007-05-28 23:00 ` Georg Bauhaus
2007-05-24 7:39 ` Dmitry A. Kazakov
2007-05-24 11:12 ` Stefan Lucks
2007-05-24 13:56 ` Dmitry A. Kazakov
2007-05-24 14:41 ` Stefan Lucks
2007-05-24 15:46 ` Dmitry A. Kazakov
2007-05-24 15:00 ` 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