copy yourself?

Colin Putney cputney at whistler.com
Fri May 23 19:35:16 UTC 2003


Jan Ziak pondered this question:

> hi. i would like to ask whether some squeaker has ever seen an object
> which  is capable of copying itself. for example, i have a glass in
> front of me -  certainly an object - but i have never seen any glass
> copying itself in front  of me when i say "copy yourself" to it. in
> contrary, i have only seen people  or machines capable of copying a
> glass. the point is that i do not believe  that any object could copy
> itself. even DNA which is said to have replicating  capabilities does
> not replicate itself as such, but requires a niche capable  of
> replicating it. so why, in smalltalk, almost every object can copy
> itself  when i send a message to it - it seems absurd to me. doesn't it
> also to you?
>
> a second problem is that the copying process depends on particularities
> of  situation in which someone or something want's to copy an object.
> copying is  context dependent. so why has every object in smalltalk
> only one method for  copying (well it has three types of copy-methods
> but the point is that the  number and meaning of them fixed).
>
> wouldn't it be more rational to have objects capable of constructing
> copies  of objects?

I myself have never seen anything copied. Ever. What is copying, after 
all, but the creation of another thing that is identical to the 
original. This is impossible, because you cannot have to things which 
are the same in every respect. So the best we can hope for is to create 
another object which resembles the original in all the respects that we 
care about.

In the case of a glass, this might be as simple as "can also hold 
water," a purely pragmatic definition of glassness. If we are holding 
an elegant dinner party, we might also care about shape, size, weight, 
and color to ensure that our place settings look good on the table. If 
we are chemists, we might care about the heat conductivity of the glass.

In the real world, objects have no intrinsic definition. We can define 
properties we are interested in and compare objects with respect to 
those properties. But the objects remain what they are regardless of 
how we represent them in our minds. Similarity is in the mind of the 
comparator. So the act of copying requires a mind  - a context, as you 
say - to define the parameters of the copying operation.

In contrast, Squeak objects do have an intrinsic definition. They are 
defined by their class. Other object-oriented systems have other 
methods of defining objects, but they all use a definition of one sort 
or another. In order to better simulate the real world, we use the 
principal of "encapsulation" to hide that definition from other 
objects. For practical reasons, encapsulation isn't strictly enforced, 
we find it useful to break it every now and then - in inspectors or the 
debugger, for example. But for the most part, we want to treat objects 
as opaque. Like objects in the real world, we (and other objects in the 
system) cannot know their essence.

This presents a problem for your idea of an external copier, copying 
the object according to it's context. Objects in Squeak are really very 
narrowly defined, unlike the real world which seems to be infinite in 
it's depth and richness. You can't examine the object in arbitrary 
ways, you can only do so in terms of it's definition - its instance 
variables, its methods, its class. But that would break encapsulation.

Luckily there *is* something that can examine an object with out 
breaking encapsulation - the object its self. So in fact, it's quite 
reasonable to have an object copy its self. It's the only thing that 
can do so.

Does that clarify anything?

Colin



More information about the Squeak-dev mailing list