comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: abstract sub programs overriding
Date: Tue, 16 Mar 2004 00:00:57 -0600
Date: 2004-03-16T00:00:57-06:00	[thread overview]
Message-ID: <105d61gprn05743@corp.supernews.com> (raw)
In-Reply-To: 1079013337.572283@master.nyc.kbcfp.com

"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:1079013337.572283@master.nyc.kbcfp.com...
> Robert I. Eachus wrote:
> > No, as I said, there are two common idioms, the first is to call the
> > parent Initialize AFTER doing any initialization work needed on the
> > fields that occur only in the child.
> >
> > procedure Initalize(Object: in out Child) is
> > begin
> >   Do_Something(Object);
> >   Initialize(Parent(Object));
> > end Initialize;
...

I have no idea what Robert is talking about here. The "common idiom" that I
use is:

procedure Initalize(Object: in out Child) is
begin
   Initialize(Parent(Object));
   Do_Something(Object);
end Initialize;

On the other issue, it's clear that a class-wide call in Initialize can be
forced to dispatch to a routine which can see uninitialized components. But
such a dispatch (which you always have to write explicitly) is a bug in
Initialize/Adjust/Finalize. You *never* want dispatching on the operative
object in the implementation of these routines, and doing such is a mistake.
It's true that Ada doesn't protect you from this mistake, but its one that
you have to work at pretty hard to make.

It's unfortunate that Ada doesn't have a sane way to call the parent
operation (using a type conversion to a specific type is ugly and
potentially a source of error if another type is inserted into the
hierarchy), because that is the most likely way to insert a dispatching call
by accident. DK, seems to want to outlaw redispatching altogether (which is
too fierce to me), but such a rule would eliminate any possibility of
accessing uninitialized components in these routines.

(Of course, in practice, default initialization of the components does most
of the work, so it's fairly rare that Initialize does anything important at
all. Which reduces the consequences of the [unlikely] error to very little
anyway.)

                     Randy.








  parent reply	other threads:[~2004-03-16  6:00 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-02 19:01 abstract sub programs overriding Evangelista Sami
2004-03-03  1:43 ` Stephen Leake
2004-03-05 15:02   ` Evangelista Sami
2004-03-05 16:15     ` Marius Amado Alves
2004-03-08 18:54       ` Adam Beneschan
2004-03-08 23:42         ` Marius Amado Alves
2004-03-05 16:26     ` Marius Amado Alves
2004-03-06  9:31       ` Simon Wright
2004-03-06 15:18         ` Evangelista Sami
2004-03-06 19:09           ` Marius Amado Alves
2004-03-07 12:35             ` Simon Wright
2004-03-07 13:39               ` Marius Amado Alves
2004-03-08 19:08               ` Adam Beneschan
2004-03-08 20:03                 ` Hyman Rosen
2004-03-09  8:51                   ` Dmitry A. Kazakov
2004-03-09 13:34                     ` Hyman Rosen
2004-03-09 14:49                       ` Dmitry A. Kazakov
2004-03-09 15:14                         ` Hyman Rosen
2004-03-09 15:56                           ` Dmitry A. Kazakov
2004-03-09 16:32                             ` Hyman Rosen
2004-03-10  9:32                               ` Dmitry A. Kazakov
2004-03-10 13:08                                 ` Hyman Rosen
2004-03-10 14:58                                   ` Robert I. Eachus
2004-03-10 16:00                                     ` Hyman Rosen
2004-03-10 18:07                                       ` Robert I. Eachus
2004-03-10 20:04                                         ` Hyman Rosen
2004-03-11  2:43                                           ` Robert I. Eachus
2004-03-11 13:55                                             ` Hyman Rosen
2004-03-12 23:02                                               ` Robert I. Eachus
2004-03-14 21:33                                                 ` Hyman Rosen
2004-03-15  5:59                                                   ` Robert I. Eachus
2004-03-15 14:39                                                     ` Hyman Rosen
2004-03-16 16:16                                                       ` Robert I. Eachus
2004-03-16 16:51                                                         ` Hyman Rosen
2004-03-16 19:54                                                         ` Hyman Rosen
2004-03-16 23:16                                                           ` Randy Brukardt
2004-03-17  1:54                                                           ` Robert I. Eachus
2004-03-16 23:14                                                         ` Randy Brukardt
2004-03-17  2:43                                                           ` Robert I. Eachus
2004-03-17 17:40                                                             ` Randy Brukardt
2004-03-18  2:39                                                               ` Robert I. Eachus
2004-03-18  5:57                                                                 ` Randy Brukardt
2004-03-18 15:03                                                                   ` Hyman Rosen
2004-03-18 20:32                                                                     ` Randy Brukardt
2004-03-19  3:59                                                                       ` Hyman Rosen
2004-03-19 19:37                                                                         ` Randy Brukardt
2004-03-16  6:00                                               ` Randy Brukardt [this message]
2004-03-11 10:09                                   ` Dmitry A. Kazakov
2004-03-11 14:10                                     ` Hyman Rosen
2004-03-11 14:59                                       ` Dmitry A. Kazakov
2004-03-11 15:40                                         ` Hyman Rosen
2004-03-11 16:28                                           ` Dmitry A. Kazakov
2004-03-11 17:26                                             ` Hyman Rosen
2004-03-12  8:53                                               ` Dmitry A. Kazakov
2004-03-12 13:09                                                 ` Hyman Rosen
2004-03-12 14:00                                                   ` Dmitry A. Kazakov
2004-03-12 14:56                                                     ` Hyman Rosen
2004-03-12 18:19                                                       ` Dmitry A. Kazakov
2004-03-12 18:34                                                         ` Hyman Rosen
2004-03-12 20:05                                                           ` Georg Bauhaus
2004-03-13 10:12                                                           ` Dmitry A. Kazakov
2004-03-12 18:07                                               ` Robert I. Eachus
2004-03-10 15:51                 ` Evangelista Sami
2004-03-11  1:38                   ` Dan Eilers
2004-03-06 23:20     ` Dan Eilers
2004-03-03 12:00 ` Marius Amado Alves
2004-03-13  7:51 ` Simon Wright
replies disabled

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