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: f4fd2,23202754c9ce78dd X-Google-Attributes: gidf4fd2,public X-Google-Thread: fac41,15edb893ef79e231 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,15edb893ef79e231 X-Google-Attributes: gid103376,public X-Google-Thread: 114809,15edb893ef79e231 X-Google-Attributes: gid114809,public X-Google-ArrivalTime: 2002-01-22 07:47:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!iad-peer.news.verio.net!dfw-peer.news.verio.net!news.verio.net!sea-read.news.verio.net.POSTED!not-for-mail Message-ID: <3C4D8AC7.37C31EEC@brising.com> From: Steven T Abell Organization: brising.com X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.lisp,comp.lang.ada,comp.lang.eiffel,comp.lang.smalltalk Subject: Re: Copying semantics molehill (was Re: True faiths) References: <9jtu3u8cq92b05j47uat3412tok6hq Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 22 Jan 2002 15:47:41 GMT NNTP-Posting-Host: 63.78.96.34 X-Complaints-To: abuse@verio.net X-Trace: sea-read.news.verio.net 1011714461 63.78.96.34 (Tue, 22 Jan 2002 15:47:41 GMT) NNTP-Posting-Date: Tue, 22 Jan 2002 15:47:41 GMT Xref: archiver1.google.com comp.lang.lisp:24981 comp.lang.ada:19183 comp.lang.eiffel:5493 comp.lang.smalltalk:18435 Date: 2002-01-22T15:47:41+00:00 List-Id: > Can anyone show an example of a situation where copying semantics really > matter? Sure. Imagine you have an object with some simple attributes, ans some connections to other complex objects, and you want to save this object to a file. A shallow copy would only take those attributes that were simple, for example, numbers and strings. A deep copy would also copy out all of the connected complex objects, and all of their connected objects, and all of their connected objects, etc. For a great many objects that you will actually build, a deep copy will eventually copy the entire image, or get stuck in a copy cycle, where some referent of the original object refers back to the original object. There are tools, such as in VisualWorks, that scan the copy graph before copying to work around this cyclic copying. They work, but they are often unavoidably slow. The exact meaning of "copy" turns out to be a *really* hard problem: there is no single answer that works in all cases. One place where copy depth is often a problem is in copying collections. The usual copy creates a duplicate collection with references to the same objects as the original collection. This might be what you want, or it might not. For this kind of copy, you have to remember that changes to a collection element will appear in *both* collections, since both collections refer to that object. A deeper copy copies the elements also, but the question arises: How deeply do you copy? Once again, there is no simple answer. You have to think very carefully about your application's needs and then code your copy semantics just as carefully. Steve -- Steven T Abell Software Designer http://www.brising.com In software, nothing is more concrete than a good abstraction.