On Thursday 06 October 2005 08:01, Gavin Kistner wrote:
> On Oct 5, 2005, at 10:17 PM, Kevin Brown wrote:
> > Which is what I just said minus the recursively.  I apologize for
> > missing that
> > crucial piece.  What was originally stated by David was that a
> > different
> > array containing the same objects was a shallow copy.  It is not
> > fully deep,
> > nor is it fully shallow.  That's all.
>
> I think you and I are still saying different things. Here's what I
> (and I believe David) am saying.
>
> a,b = 'a', 'b'
> c = [ a, b ]
> same = c
> shallow = c.dup
> deep = [ a.dup, b.dup ]
>
> 'same' is a reference to the same array. It is not, in any way, a
> copy. This seems to be what you called a 'shallow copy'.

I understand it's not a copy.  In C++ terminology that I learned it's called a 
shallow copy due to the fact that it contains a 'copy' of the data but two 
deletes will crash becase there are only really two references.  The default 
copy constructor will do this for you if you don't overload it when you do 
dynamic memory allocation.  Hence shallow copy.  I didn't decide this 
terminology, and it may disagree with what many say on the subject.  That's 
fine, it's the terminology I learned, and that's all.

> 'shallow' is what I would call a shallow copy - you can push a new
> element onto the array without affecting the original,

The terminology I learned states that any shallow copy did not duplicate any 
of the elements, just another reference (pointer) pointing to the original.  
I'm not trying to argue, because I really don't care, just trying to clarify 
what I was saying before.  I understand that no actual copying takes place 
whatsoever, except that in C++ you copy the value of the pointer to the new 
one.

> but if you 
> mutate the existing elements in the array, you affect the elements in
> the original. (For example, shallow[0]<<'HEY'  will affect c[0].)
> This seems to be what you called a 'deep' copy.

Because usually in C++ you only manage one level down.  Any object1 = object2 
that you do will be managed by the objects themselves with their own 
assignment operator or copy constructor, negating the need to traverse down 
and do a 'full' deep copy.

> 'deep' is what I would call a deep copy. (Although normally I would
> use a more automated technique to create it :)

I would call that deep as well, I'm just not used to having deep to a certain 
level copies as it's hard to achieve in C++.  You either get a reference or a 
full copy tree.