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,342dcd67e9ca73ee X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!blackbush.cw.net!cw.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: tagged record child: override constructor? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: <1126591134.797303.318920@z14g2000cwz.googlegroups.com> <1uri5gd2n7om0.1ujkzb26ayxdx.dlg@40tude.net> <1126625009.709876.226260@f14g2000cwb.googlegroups.com> <225337460.SlYKbeB8eD@linux1.krischik.com> <87vf14him5.fsf@ludovic-brenta.org> <1idpvzxcxfckw.mrs8nw3eu4ks$.dlg@40tude.net> <13wyu4lwsmzmz.ktc3t2av54yv$.dlg@40tude.net> <1126705974.984997.227590@z14g2000cwz.googlegroups.com> <1126718176.448703.193860@g44g2000cwa.googlegroups.com> <1aroipmwspnb8.zqxtxhb4t06u$.dlg@40tude.net> <1126731371.081850.90860@g44g2000cwa.googlegroups.com> <12v93t1k4i81i$.sm5jmg8q3lpk$.dlg@40tude.net> <1126790380.573573.78220@g44g2000cwa.googlegroups.com> Date: Thu, 15 Sep 2005 19:45:42 +0200 Message-ID: <1w82ustqd4vak$.mv9c3tcxa6sx.dlg@40tude.net> NNTP-Posting-Date: 15 Sep 2005 19:44:40 MEST NNTP-Posting-Host: 6c405ce5.newsread2.arcor-online.net X-Trace: DXC=7Pe[Pn?D9BSA]`4:;olJY9 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:4735 Date: 2005-09-15T19:44:40+02:00 List-Id: On 15 Sep 2005 06:19:40 -0700, Hyman Rosen wrote: > Dmitry A. Kazakov wrote: >> Which mistake? Again, it is solely the actual object's *type* which >> determines dispatch. > > The mistake of not calling the overridden method of the actual > type of the object rather than of the declared type. There is no actual type, there is only the type specified by the contract. That's the whole point. > In OO > programming, by-reference objects have two types, their declared > base type and their actual created type. That's your view on OO, which is clearly inconsistent with the notion of types. Try to ask yourself simple questions: is "by-reference" a type property? Why by-copy objects (of which type?) have one (which?) type while by-reference objects (of which type?) have more than one? It is rubbish. In a typed language an object has a type, only one type. > In OO programming, it is > expected by the programmers that a call to a potentially overridden > function using a base by-reference object will dispatch to the > overridden function. If the language claims to support OO but then > makes it easy to call these methods in such a way that overriding > doesn't happen, and without warning, then the language has introduced > a dangerous trap. No. Trap is when the declared type does not determine what's going on. >> It is 100% safe, intuitive and unambiguous. > > It is not intuitive at all, except to people whose intuition has > been warped. It's just plain wrong. You haven't presented anything to support this point, other than assumptions about some hypothetical newbies. I (again) formulate the properties of Ada's model: 1. The contract model 2. No space overhead 3. No run-time overhead caused by unnecessary re-dispatch 4. Pure OO (all types can have classes) 5. Compatible to multiple dispatch 6. Consistent with multi-methods 7. Compatible with class construction (dispatching from constructors/destructors can be ) 8. Compatible with assignment, abstract factory and all other cases, where the result is dispatching. 9. Polymorphic object can be coped 10. Can return polymorphic objects on the stack 11. Can aggregate polymorphic objects in other objects 12. Covariant in all parameters Now show me how C++ or Java could accomplish 1..12. >> No. It calls B::g() which was inherited from A. I don't care if code of >> B::g() and A::g() share memory or not. They are different functions because >> their signatures are different. > > No, they are the same function. If, for example, I included a static > variable within it, calls to A::g() and B::g() would see the same > variable. And for that matter, simply write this: > #include > #include > struct A { void g(); }; > struct B : A { }; > int main() { std::cout << (&A::g == &B::g) << "\n"; } > and you'll see whether the compiler thinks they're the same or not. What should that code prove? That pointers to members is a total mess in C++? Everybody knows it. >> It does not. It calls B::f() from B::g() > > No. There is no B::g separate from A::g. I don't know what "separate" members are. Do you mean memory location? Why should I care of? > Inherited functions are > not copies, they are the same function. They cannot be same because they act on different types. You cannot call B::g() on A. The same question again, is C++ typed? > There is no code you can > write which will demonstrate a difference. class A { public : void g(); }; class B : public A {}; B * Y = new B; A * X = Y; X->B::g (); // Error, how so? X is of B, or maybe not quite? Y->B::g (); // OK -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de