Method clone vs shallowCopy
Last updated at 4:06 pm UTC on 24 April 2017
Sun, Apr 23, 2017 at 8:57 PM
To: The general-purpose Squeak developers list
On Sun, 23 Apr 2017, Tobias Pape wrote:
On 23.04.2017, at 20:20, firstname.lastname@example.org wrote:
uses #shallowCopy instead of #clone
just curious, why?
Both methods are intended to do the same thing. IIRC #shallowCopy is the cross-dialect method for this purpose, while #clone came with Morphic from Self.
They both use primitive 148 to copy the object.
Object >> #clone used to raise an error when the primitive failed, but that might have just been oversight. Now both methods try to fall back to #basicNew(:) and manually copy the fields, which is what #shallowCopy has always been doing.
However, #clone's fallback code now differs from #shallowCopy's, the latter having the newer timestamp, but the former seems to be simpler, because it relies on #copyFrom:.
I can't really tell which fallback code is better, so I'll leave that to someone more knowledgeable.
So I suggest we
- update #shallowCopy if needed to have the best fallback code
- rewrite senders of #clone from the Trunk to use #shallowCopy
- deprecate Object >> #clone and make it be a send of #shallowCopy
- remove other implementors of #clone
P.S.: this was done long ago in Pharo