Object>copyFrom:

Alan Lovejoy sourcery at pacbell.net
Mon Jul 5 02:25:39 UTC 1999


I was porting some code to the latest version of Squeak from a
Squeak-based project that I had worked on a year or so ago
(you know, that infamous project at Interval Research), when
I was surprised by a mysterious bug that seemed to have crept
in to the code.  I quickly deduced that the #copyFrom: method
was not working correctly, so I went to SequenceableCollection
to go fix it.

Problem was, there was no such method in SequenceableCollection!
I know for a fact that it used to be there.  It's defined meaning used
to be equivalent to "sef copyFrom: anIndex to: self size".  So,
the next obvious question was, if the method's no longer there,
where did it move to (since the message was being understood).
Answer: to class Object!  Whoa, Nellie.  We definitely are not
in Kansas anymore. I object (no pun intended).

Firstly, such a drastic change in the meaning of a widely-used
base system method should only happen when something is very
wrong with its old meaning.

Secondly, the message selector #copyFrom: is very similar to
a bevy of message selectors in SequenceableCollection and
its various subclasses.  The semantics of the selector #copyFrom:
would conventionally be related, in a very precise and well-defined
way, to methods with selectors such as #copyFrom:to:, #copyTo:,
#copyReplaceFrom:to:with:, #copyReplaceFrom:with:, etc.  The
method #copyFrom: in Object does not have the semantics one
would expect, based on the semantics of selectors such as
#copyFrom:to: and #copyTo:.

Finally, it is at least...controversial...to have a method in class
Object that "copies all instance variables of the same name"
between objects, regardless of class.  As the method itself
notes, this is potentially...problematical.  I would suggest that
a method with such puissant, indiscriminant function have a
name less innocuous and everyday than the rather harmless-
sounding #copyFrom:.

Perhaps #copyInstanceVariablesWithSameNamesFrom:
would be a better, less potentially misleading name.  Better yet,
define a method that copies all instance variables with matching
names from one object to another, but put it in some class whose
role or function deals with low-level system concerns.

--Alan

Content-Type: text/x-vcard; charset=us-ascii;
  name="sourcery.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Alan Lovejoy
Content-Disposition: attachment;
  filename="sourcery.vcf"

Attachment converted: Anon:sourcery.vcf 8 (TEXT/R*ch) (0000AD93)





More information about the Squeak-dev mailing list