comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Safety of the Booch Ada 95 Components
Date: 1999/12/10
Date: 1999-12-10T00:00:00+00:00	[thread overview]
Message-ID: <3851c7b9_4@news1.prserv.net> (raw)
In-Reply-To: t790326901.fsf@calumny.jyacc.com

In article <t790326901.fsf@calumny.jyacc.com> , Hyman Rosen 
<hymie@prolifics.com>  wrote:

> In C++, class objects are copied through a class method called the
> copy-constructor, to allow for resource control.

Data structures (in Ada95) are written as generics that accept the
container item as a nonlimited generic formal private type:

generic
  type Item_Type is private;
package Stacks is ...;

The "copy constructor" in Ada95 is just the assignment operator that
comes with Item_Type.  Typically, the client of the assignment operator
(here, the implementation of the Copy operation for stack types) assumes
that assignment doesn't raise an exception.

We make this assumption per the "design-by-contract" model.  If you give
me an assignment operator that doesn't work, and it raises an exception
(say), then yes, that would leave the target object in an inconsistent
state.

If you don't like that, then don't give me a broken assignment operator.

> If an exception is thrown during copy-construction of one of the elements,
> it's possible that the target data structure may be left in an invalid state.

I suppose if you don't trust your client's assignment operator, then you
could make a copy of the target object, clear the target, and then do
the copy.  If there's an error during assignment, then you use the copy
of the target to restore the target back to its original state, and then
reraise the exception.

(But then again, I don't know how you would even implement this.  How do
you make a copy of the target, if you can't trust the copy constructor
for items?)

But this is an awfully heavy way to implement a Copy operation for a
data structure.  The canonical implementation of a Copy operation should
choose the more efficient implementation, which assumes that assignment
works (again, per DBC).

If you don't like the canonical Copy, then just extend the abstraction
with a child operation implemented using the pessimistic algorithm
(which I'm not convinced is even implementable).

--
Why stop at evolution and cosmology, though? Let's make sure that the
schoolkids of Kansas get a really first-rate education by loosening up
the teaching standards for other so-called scientific ideas that are,
after all, just theories. The atomic theory, for example. The theory of
relativity. Heck, the Copernican theory--do we really know that the
universe doesn't revolve around the earth?

John Rennie, Scientific American, Oct 1999




  reply	other threads:[~1999-12-10  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-10  0:00 Safety of the Booch Ada 95 Components Harry Erwin
1999-12-10  0:00 ` Matthew Heaney
1999-12-10  0:00   ` Harry Erwin
1999-12-12  0:00     ` Simon Wright
1999-12-12  0:00       ` Harry Erwin
1999-12-13  0:00         ` Simon Wright
1999-12-10  0:00   ` Hyman Rosen
1999-12-10  0:00     ` Matthew Heaney [this message]
1999-12-11  0:00       ` Harry Erwin
1999-12-12  0:00         ` Robert Dewar
1999-12-12  0:00           ` Harry Erwin
1999-12-13  0:00           ` Kent Paul Dolan
1999-12-13  0:00             ` Simon Wright
1999-12-13  0:00             ` Ted Dennison
1999-12-13  0:00             ` Robert I. Eachus
1999-12-13  0:00       ` Hyman Rosen
1999-12-13  0:00         ` Robert I. Eachus
1999-12-14  0:00           ` Simon Wright
1999-12-15  0:00             ` Harry Erwin
1999-12-15  0:00             ` Mats Weber
1999-12-17  0:00               ` Simon Wright
1999-12-14  0:00         ` Matthew Heaney
1999-12-10  0:00     ` Harry Erwin
1999-12-10  0:00 ` Simon Wright
1999-12-12  0:00   ` Simon Wright
1999-12-12  0:00     ` Matthew Heaney
1999-12-12  0:00   ` Harry Erwin
1999-12-13  0:00     ` Simon Wright
1999-12-13  0:00 ` Tucker Taft
replies disabled

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