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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,436e4ce138981b82 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-15 22:01:21 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: abstract sub programs overriding Date: Tue, 16 Mar 2004 00:00:57 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <105d61gprn05743@corp.supernews.com> References: <1078776213.376775@master.nyc.kbcfp.com> <1078839257.157439@master.nyc.kbcfp.com> <5cmr40t76va200betf07b7bd6er05ltto9@4ax.com> <1078845298.702789@master.nyc.kbcfp.com> <0ipr40thtf86b520a0qdi003aj87gtuhd4@4ax.com> <1078849973.701176@master.nyc.kbcfp.com> <1078924150.268074@master.nyc.kbcfp.com> <1078934469.744922@master.nyc.kbcfp.com> <1078949096.760629@master.nyc.kbcfp.com> <1079013337.572283@master.nyc.kbcfp.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:6337 Date: 2004-03-16T00:00:57-06:00 List-Id: "Hyman Rosen" 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.