[comp.lang.eiffel] PEEVES

marcap@concour.CS.Concordia.CA (Marc Pawlowsky) (06/09/89)

>Please repost this to comp.lang.eiffel for me.  Our news posting
>software has been broken for a long time and I don't know when it will
>be fixed.

Please reply to author not me.

Subject: pet peeves re := and deepCopy
Summary: neither problem is real
Reply-To: deutsch@parcplace.com (L. Peter Deutsch)
Organization: ParcPlace Systems, Mountain View, CA

1) Re the "inconsistency" of :=.  You are confusing the notions of
identity, primitiveness, and equality.  For immutable objects (such as
numbers and characters), regardless of whether they enjoy special
implementation, an argument can be made that "identity" is not a useful
concept, since two immutable objects with the same contents will behave
the same under all circumstances.  If you decide that in your language
every object has a hidden, immutable piece of state called its
"identity", well and good, but then you have to pay a very heavy
performance price (you have to leave enough room in every object, even
integers, for this unique "identity").

I believe a better approach is to take the point of view that the
"identity" of an immutable object is a function of its contents, i.e.,
that immutable objects with the same (client-visible) contents really
cannot be distinguished.  This has nothing to do with whether the object
is "primitive".  As a consequence, whether := copies an immutable object
or not becomes entirely a matter of implementation with no semantic
consequences.

2) deepCopy is not a semantically useful notion.  Where do you stop?  Do
you copy classes as well as contents?  If an object has a reference to
some widely shared data structure, do you copy that entire structure?
What about references to objects like Symbols (in Smalltalk), where
there is an invariant requiring unique representation of Symbols with
the same contents?

I believe providing a deepCopy operation is a mistake.  If it were up to
me, it would be removed from the Smalltalk-80 system.

	L. Peter Deutsch

marcap@concour.CS.Concordia.CA (Marc Pawlowsky) (06/09/89)

> deutsch@parcplace.com (L. Peter Deutsch) writes
>
>2) deepCopy is not a semantically useful notion.  Where do you stop?  Do
>you copy classes as well as contents?  If an object has a reference to
>some widely shared data structure, do you copy that entire structure?
>What about references to objects like Symbols (in Smalltalk), where
>there is an invariant requiring unique representation of Symbols with
>the same contents?
>
>I believe providing a deepCopy operation is a mistake.  If it were up to
>me, it would be removed from the Smalltalk-80 system.

The deepCopy of Smalltalk is the same as Clone in Eiffel.  It copies 
the first level of pointers.  A common problem I have is that I am
working with mutable objects.  I am giving one specific example, but
I have hit this trouble often.

Gene = integer
Chromosome = set of genes
Population = set of chromosomes

A permissable operation on the population is "mutation" which changes a
genes value randomly with probability p(x).

A comparison is needed between the before and
after populations.

To do the comparison it is necessary to keep a copy of the population.
So, YES, the entire data structure should be copied.  If it takes a lot
of space the programmer must be careful.  This is a normal programming
problem.