clone vs shallowCopy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
43 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: clone vs shallowCopy

Stan Shepherd
Stéphane Ducasse wrote
any bunch of cool tests before hacking?


On Jan 13, 2010, at 9:53 AM, Alain Plantec wrote:

> Lukas Renggli a écrit :
>> I suggest everybody to have a quick look at VW:
>> - they have #copy and #postCopy as we do
>> - they have #shallowCopy that is used from #copy as we do
>> - they have #dcopy (what a horrible name) that is implemented in a
>> similar way to what I suggested for #deepCopy
>>
>> There is nothing else.
>>
> yes, I think we should adopt this with (dcopy -> deepCopy).
> Alain
>> Lukas
>>
there's one (not a bunch)  at: http://pharo.googlecode.com/issues/attachment?aid=7298911011553982520&name=CircularInstVarTest.st
Reply | Threaded
Open this post in threaded view
|

Re: clone vs shallowCopy

Eliot Miranda-2
In reply to this post by Stéphane Ducasse


On Tue, Jan 12, 2010 at 11:55 PM, Stéphane Ducasse <[hidden email]> wrote:
Now it would be nice to clean that because in VW you have copy, shallowCopy and postCopy and it works.
They removed veryDeepCopy and other friends even when they were at the time were they could burn engineering time
on that.


I think you'll find VW has Object>>dcopy, which is essentially the same as veryDeepCopy, a structure-preserving graph copy.  So VW has shallowCopy, copy built upon shallowCopy and postCopy, and dcopy.  IMO all three are useful.  Old deepCopy is not.
 
So for me clone is one too many.
And worse cloning and object cannot be a shallowCopy semantics. it should be more a veryDeepInnerVeryCopy (I could not resist sorry)
Of course we already clean and remove the veryDeepInnerCopy.... No comment.

>>> - #copy is the normal copy operation. It should be used by default and
>>> never overridden. It calls #postCopy that can be overridden to have
>>> class specific copy semantics.
>>>
>>> - #shallowCopy does a shallow copy. It should never be overridden and
>>> only be used if you want to get these very specific semantics.
>>>
>>> - #deepCopy does a deep copy. It should never be overridden and only
>>> be used if you want to get these very specific semantics.
>>>
>>> - #clone comes from eToys and Morphic (AFAIK). It implements some
>>> other copy semantics than #copy. I don't think that anybody should
>>> call this method, other than code that depends on this particular copy
>>> behavior.
>>
>> we should copy that in Object class comment and all the methods
>>
>>
>> where do you see that it is morphic related for me clone is only implemented
>> on character, Boolean, Object, SMalltInt symbol, UndefinedObject
>
> Back in the old days, Squeak 1.1 didn't have primitive 148 (which is now used by both #shallowCopy and #clone). #shallowCopy was the way to create a "one-level copy" of an Object. It had the same code as today, but with no primitive.
> Primitive 148 was introduced somewhere between 1.1 and 1.19 (note that 1.2 came after 1.19). 1.19 (and probably earlier versions, but not 1.1) had #clone which was primitive only and #shallowCopy which didn't use the primitive. Morphic was being ported to Squeak at the time and it was the only user of #clone. Morphs were copied by #clone which was pretty fast, while other objects used #shallowCopy. Later the use of #clone started to spread, until primitive 148 was added to #shallowCopy. Sends of #clone were replaced with #shallowCopy and #copy, but #clone was kept, probably for backwards compatibility.
>
> #clone and #shallowCopy have a difference in their semantics. If the vm cannot allocate enough space for the new object, #clone raises an error immediately, while #shallowCopy signals the low space semaphore, so the image or the user can do something, then retries the copying.
>
>
> Levente
>
>>
>>>
>>> This is exactly the same problematic as with #=. There can't be just
>>> one #=. Other clients might consider other things when comparing
>>> objects.
>>>
>>> Lukas
>>>
>>> --
>>> Lukas Renggli
>>> http://www.lukas-renggli.ch
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: clone vs shallowCopy

Stéphane Ducasse
In reply to this post by Stan Shepherd
Thanks I linked the two issues

On Jan 13, 2010, at 2:33 PM, Stan Shepherd wrote:

>
>
> Stéphane Ducasse wrote:
>>
>> any bunch of cool tests before hacking?
>>
>>
>> On Jan 13, 2010, at 9:53 AM, Alain Plantec wrote:
>>
>>> Lukas Renggli a écrit :
>>>> I suggest everybody to have a quick look at VW:
>>>> - they have #copy and #postCopy as we do
>>>> - they have #shallowCopy that is used from #copy as we do
>>>> - they have #dcopy (what a horrible name) that is implemented in a
>>>> similar way to what I suggested for #deepCopy
>>>>
>>>> There is nothing else.
>>>>
>>> yes, I think we should adopt this with (dcopy -> deepCopy).
>>> Alain
>>>> Lukas
>>>>
>>
>>
>
> there's one (not a bunch)  at:
> http://pharo.googlecode.com/issues/attachment?aid=7298911011553982520&name=CircularInstVarTest.st
> --
> View this message in context: http://n2.nabble.com/clone-vs-shallowCopy-tp4290815p4348552.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
123