Re: Generics vs. Message passing: object namespaces

Pascal Costanza <[email protected]> Sat, 24 Feb 2007 15:24:47 +0100
Newsgroups gmane.comp.lang.lightweight
Message-ID <[email protected]>
On 24 Feb 2007, at 03:56, [email protected] wrote:

>> Here is the problem. Consider two interfaces in Java:
>>
>> ...
>>
>> This doesn't compile. There is no way in Java to define a class that
>> can implement both I1 and I2. If I1 and I2 are from different vendors
>> and you need to implement both interfaces, you're screwed.
>
>     Here is the problem: this example uses name collision as a  
> result of
> multiple inheritance, and the complaint at hand wrt CLOS is a problem
> that arises even when multiple inheritance is not involved.  Clearly,
> the latter situation is more serious -- i.e., more likely to be more
> common -- hence my claim that the problem arises sooner with generic
> dispatch.

I find it hard to tell what is more common and what is not. None of  
us has any empirical evidence for one position or the other. We are  
just exchanging toy examples here. I don't want to make  
generalizations based on toy examples.

But here is another one. Assume someone has written the following  
code in a hypothetical dynamically typed language:

class ObjectContainer {

   objects;

   ObjectContainer(objs) {
     this.objects = objs;
   }

   void draw() {
     foreach (object: objects) {
       object.draw();
     }
   }
}

Now, someone uses that code as follows:

new ObjectContainer(new List(picture, gun, blood)).draw();

Good idea?

> That an example can be found that shows a problem is not
> compelling, it is a question of comparing the problems in the two
> systems.  In this case its a bit apples and oranges I think.  As an
> aside, this is not a problem endemic to object dispatch, but Java's
> implementation.  In C++ and presumably other languages one could
> explicitly resolve the conflict within the class definition.

Sure, because C++ has a namespace management system that is more  
advanced than Java's.

Maybe this got lost in the noise, but in CLOS I do the following:

(defpackage weapons
   (:export draw))

(defpackage graphics
   (:export draw))

Then I can say in a different piece of source code:

(defpackage mypackage
   (:use :weapons))

...

     .... draw ....    ;; <= this refers to weapons:draw

...


So I can get all the short names whenever I want them.

The only thing that is not possible is this:

(defpackage mypackage
   (:use :weapons :graphics))

I find it hard to believe that you want to write code that is at the  
same time about two different kinds of concrete concepts. If that is  
the case, it is rather exceptional and it is probably a good idea  
anyway to be explicit about what you are talking about.


Pascal

-- 
Pascal Costanza, mailto:[email protected], http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium