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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8acd4291c317f897 X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,8acd4291c317f897 X-Google-Attributes: gid109fba,public From: "Matthew Heaney" Subject: Re: Safety of the Booch Ada 95 Components Date: 1999/12/10 Message-ID: <3851c7b9_4@news1.prserv.net>#1/1 X-Deja-AN: 559246570 Content-transfer-encoding: 7bit References: <1e2lds4.7trgj21rgj9i0N%herwin@gmu.edu> <38512921_3@news1.prserv.net> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 11 Dec 1999 03:40:41 GMT, 129.37.62.147 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada,comp.lang.c++ Date: 1999-12-10T00:00:00+00:00 List-Id: In article , Hyman Rosen 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