comp.lang.ada
 help / color / mirror / Atom feed
From: "Hyman Rosen" <hyman.rosen@gmail.com>
Subject: Re: tagged record child: override constructor?
Date: 14 Sep 2005 06:52:55 -0700
Date: 2005-09-14T06:52:55-07:00	[thread overview]
Message-ID: <1126705974.984997.227590@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: 13wyu4lwsmzmz.ktc3t2av54yv$.dlg@40tude.net

Dmitry A. Kazakov wrote:
> 1. It is space inefficient. To have T and T'Class same requires keeping the
> type tag in all Ts, while it is only necessary in T'Class.

No Ada implementation takes this approach, though.
They all keep a type tag in every tagged object.

> 3. It is inefficient, because it has to dispatch everywhere

In C++, however, you have already declared some functions to be
dispatching (virtual) and some not. For those functions which are
virtual, dispatching is what's wanted. How many Ada newbies get
completely confused trying to figure out what dispatches and what
doesn't? Do any of them write T'Class the first time?

> 4. It is error-prone because of enforced re-dispatch

It is error-prone not to dispatch, because the first thing everyone
learns about OO is that methods dispatch! It's only after significant
hair-pulling that an Ada newbie will realize why his overriden methods
are not being called.

> 5. When T and T'Class are same, objects have identity.

Huh? All type tags for a given type are identical. Why does embedding
a type tag in an object give it any more identity than not doing so?

> The implementation of Foo stay consistent no matter what a derived type
> would do with Bar.

Except that when the programmer overrides Bar for derived types,
he's going to be monumentally confused as to why Foo isn't calling
it. Foo is going to be consistent, but as far as the programmer is
concerned, it's going to be consistently incorrect.

> Re-dispatch usually indicates a design problem.

What nonsense!

> Yes, they do as if they wouldn't. To me it is that they don't.

As has been repeatedly demonstrated to you, this is just wrong.
Once again, here is the code:

    struct A {
        virtual void f() { print("A"); }
        void g() { f(); }
        A() { g(); }
        ~A() { g(); }
    };
    struct B : A {
        void f() { print("B"); }
        B() { g(); }
        ~B() { g(); }
    };
    int main() { B b; }

This will print "ABBA", demonstrating that dispatching is occuring
within g() even when it is called from a constructor or destructor.




  reply	other threads:[~2005-09-14 13:52 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13  5:58 tagged record child: override constructor? sean.gilbertson
2005-09-13  6:39 ` David Trudgett
2005-09-13  7:32 ` Dmitry A. Kazakov
2005-09-13  7:56   ` tmoran
2005-09-13 15:23   ` sean.gilbertson
2005-09-13 17:37     ` Martin Krischik
2005-09-13 19:29       ` Ludovic Brenta
2005-09-14  7:49         ` Dmitry A. Kazakov
2005-09-14  9:05           ` Maciej Sobczak
2005-09-14 13:20             ` Dmitry A. Kazakov
2005-09-14 13:52               ` Hyman Rosen [this message]
2005-09-14 16:47                 ` Dmitry A. Kazakov
2005-09-14 17:16                   ` Hyman Rosen
2005-09-14 20:20                     ` Dmitry A. Kazakov
2005-09-14 20:34                       ` Georg Bauhaus
2005-09-14 20:56                       ` Hyman Rosen
2005-09-15  7:31                         ` Dmitry A. Kazakov
2005-09-15 13:19                           ` Hyman Rosen
2005-09-15 13:45                             ` Maciej Sobczak
2005-09-15 17:45                             ` Dmitry A. Kazakov
2005-09-15 18:54                               ` Hyman Rosen
2005-09-16  9:32                                 ` Dmitry A. Kazakov
2005-09-16 14:52                                   ` Hyman Rosen
2005-09-16 15:33                                     ` Jean-Pierre Rosen
2005-09-16 18:37                                       ` Hyman Rosen
2005-09-16 21:03                                     ` Dmitry A. Kazakov
2005-09-16 21:33                                       ` Hyman Rosen
     [not found]                                         ` <98ox2x9xvj9z.1uh92dslhvt4g.dlg@40tude.net>
2005-09-17 12:47                                           ` Georg Bauhaus
2005-09-17 15:56                                             ` Dmitry A. Kazakov
2005-09-14 16:14           ` Martin Krischik
2005-09-14 16:57             ` Dmitry A. Kazakov
2005-09-14 18:35               ` Martin Krischik
2005-09-14  9:28         ` Alex R. Mosteo
2005-09-14 16:10         ` Martin Krischik
2005-09-13  9:33 ` Georg Bauhaus
2005-09-13 16:37 ` Jeffrey Carter
2005-09-13 18:55   ` Robert A Duff
2005-09-13 22:18     ` Jeffrey Carter
replies disabled

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