comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: abstract sub programs overriding
Date: Thu, 18 Mar 2004 14:32:08 -0600
Date: 2004-03-18T14:32:08-06:00	[thread overview]
Message-ID: <105k1qt2i88gt1c@corp.supernews.com> (raw)
In-Reply-To: 1079622255.263633@master.nyc.kbcfp.com

"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:1079622255.263633@master.nyc.kbcfp.com...
> Randy Brukardt wrote:
> >>What you as an author want is that any object that is correctly
> >>initialized will be finalized, that any object which is not initialized
> >>will not be finalized, and there are no objects in the middle.
> >
> > Right, but that's a tough property to guarentee, particularly if you
want to
> > to be reasonably secure from abort and the like.
>
> C++ does its best to guarantee this, but will abort the program if,
> during the automatic destruction of objects as a result of a thrown
> exception, another exception propagates out of one of these destructors.
> There's only so much you can do in cases like that. Even Ada raises a
> program error in such cases.

I was thinking about task abort, which can leave stuff in pretty much any
state. You can protect against exceptions, but you can't protect against
abort. (With two important exceptions: protected operations and
Initialize/Adjust/Finalize routines are abort-deferred.)

> But if you write your destructors so that exceptions can never escape
> (which is the recommended style, because throwing an exception out of
> a function "means" that the function cannot fulfill its duty, whereas
> a destructor has no choice in the matter, since the object is being
> destroyed regardless of what the destructor thinks about it), then C++
> provides that guarantee - objects are constructed once and any object
> which is constructed will be destructed. (Barring manual intervention,
> of course.)

I think that is true in Ada as well. The question that Robert Eachus is
thinking about is what happens if an Initialize routine propagates an
exception (or a constructor in C++). In such a case, the object could be
partially initialized. Ada says that the top-level finalizer will not be
called in that case (although the finalize of controlled components that
completed initialization will be called).

This also covers abort during initialization (before Initialize is called,
since it is abort-deferred). But abort of an assignment can cause an object
to end up in a goofy state (say, if it happens between the target
finalization and the Adjust).

>  > I think it is best to depend primarily of a valid flag
>
> The problem with a valid flag is that it pushes the responsibility for
> validity testing out to all the methods. One of the goals of having a
> constructor in OO was to localize object construction in one place, so
> every other method could assume that the object was in a consistent and
> valid state.

Not necessarily. What I was thinking of was a flag for the use of
Initialize/Adjust/Finalize -- so that Finalize does nothing if it is not
set. That's absoletely necessary if you use Robert's aggregate assignment,
because Finalize will be called with an object on which Initialize has not
run. And it's always possible in the Ada model that Finalize will be called
twice. OTOH, any (other) method of the type can assume that the object is
valid. (This presumes that Initialize isn't calling methods, but that is
under the control of the programmer.)

> > (For someone who claims to not know Ada very well, Hyman knows Ada very
>  > well. He should join the ARG. :-) We could use him.)
>
> :-) It's mostly that I understand in pretty excruciating detail how
> things work in C++ (and in Java, to some extent), and the reasons for
> those behaviors. When I see that Ada does something differently, I can
> try to figure out whether those reasons will have an effect that C++
> was designed to avoid. (Note that I'm not claiming C++ is better, I'm
> just comparing effects of different decisions.)

Which was my point. Many ARG members don't know C++ that well, so we may
miss subtilies of the design. Your input is very useful that way. It would
be especially useful on the new features of Ada 2005 (like interfaces),
while we still can repair screw-ups.

                 Randy.






  reply	other threads:[~2004-03-18 20:32 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 [this message]
2004-03-19  3:59                                                                       ` Hyman Rosen
2004-03-19 19:37                                                                         ` Randy Brukardt
2004-03-16  6:00                                               ` Randy Brukardt
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