From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2ff5c149712ec0eb X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feed.tweaknews.nl!195.96.0.7.MISMATCH!newsfeed.utanet.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada Interfaces and the Liskov Substitution Principle Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1179953657.839272.160320@a26g2000pre.googlegroups.com> <1179991769.376381.252010@m36g2000hse.googlegroups.com> <12h6mi42jcha0.7f9vfsnihjwr$.dlg@40tude.net> <1180011507.159515.46920@o5g2000hsb.googlegroups.com> Date: Thu, 24 May 2007 15:42:36 +0200 Message-ID: NNTP-Posting-Date: 24 May 2007 15:40:29 CEST NNTP-Posting-Host: d91c0053.newsspool4.arcor-online.net X-Trace: DXC=C@]dI^S>XcO[6=1B@oB@@@4IUKkgBNZKQk65Ni5G X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:15908 Date: 2007-05-24T15:40:29+02:00 List-Id: On 24 May 2007 05:58:27 -0700, Maciej Sobczak wrote: > On 24 Maj, 10:02, "Dmitry A. Kazakov" > 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