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
Colin Putney pondered this reaction to my question:
On Fri, 23 May 2003 12:35:16 -0700, Colin Putney wrote
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
thanks for your reaction, it is a nice one.
i have concluded from your reaction the following: we can state that the existence of a #copy method is consequence of having encapsulation ... and if we would like to have encapsulation then it forces us to have such #copy yourself methods as in squeak.
my reaction and question then is: why do we not allow access to the internal state of an object O1 only to the object R which replicates O1 ? the encapsulation is not broken in this case because objects expect R do not have access to the internal state of O1.
On Wednesday, May 28, 2003, at 07:48 AM, jan ziak wrote:
thanks for your reaction, it is a nice one.
i have concluded from your reaction the following: we can state that the existence of a #copy method is consequence of having encapsulation ... and if we would like to have encapsulation then it forces us to have such #copy yourself methods as in squeak.
my reaction and question then is: why do we not allow access to the internal state of an object O1 only to the object R which replicates O1 ? the encapsulation is not broken in this case because objects expect R do not have access to the internal state of O1.
But encapsulation *is* broken with respect to R. That's significant, because encapsulation (and it's corollory, polymorphism) is the fundamental principal behind object orientation. In fact, it wouldn't be a stretch to say that the quality of code (OO or otherwise) is determined by the degree to which it enforces encapsulation.
Your proposal above would require a second "replicator" class for every class in the system. The squeak image currently has 1280 classes in it, with thousands more in external packages. Do you really want to replace a few methods on object with thousands of classes? Even if you took the time to write all those classes, it would be a nightmare to maintain. If you write a special replicator generator, you break encapsulation even more, because you remove the ability of objects to override the standard copying behaviour provided by Object.
Of course, if having objects copy themselves bothers you so much that you want to break encapsulation anyway, go ahead. Squeak is an open system, and you can do anything you like. I don't think your changes would be adopted by the rest of the community, though.
This thread has gone on too long. I won't post on this topic again.
Colin
On Wed, 2003-05-28 at 10:48, jan ziak (or a reasonable facsimile) wrote:
i have concluded from your reaction the following: we can state that the existence of a #copy method is consequence of having encapsulation ... and if we would like to have encapsulation then it forces us to have such #copy yourself methods as in squeak.
my reaction and question then is: why do we not allow access to the internal state of an object O1 only to the object R which replicates O1 ? the encapsulation is not broken in this case because objects expect R do not have access to the internal state of O1.
Jan:
1) Smalltalk (and any other object-oriented language) works fine the way it is. Try to understand it before you fix it. (remember that clock you tried to "fix" when you were a child?)
2) In this post, you are simply restating a question (the "copier" conundrum) that you asked before. I believe Colin Putney has adequately answered that question. Please read and accept his post.
3) Your initial questions (about copying, text manipulation, etc.) arise from pushing an analogy (the "object" analogy) too far. All analogies break down eventually when you examine their details, even exceptionally useful ones such as the object analogy. "Objects" in Smalltalk are not the SAME as 'real' (whatever that means) objects, even though the analogy ("they are LIKE real objects in certain aspects") is sometimes useful. Again, Goran's* post has clearly explained this and I believe it settles the issue.
4) The philosophical questions raised (reality vs. perception, etc.) are most definitely off-topic. They remind me of why I stopped studying philosophy. I prefer to just write code that does stuff.
5) Any thread eventually says everything that is worth saying about a subject. Any further posting (AFTER this post, of course :-) can only restate things that have already been said.
* (Goran: Excuse me, I don't know how to produce the proper accent in this e-mail client.)
squeak-dev@lists.squeakfoundation.org