Re: Nice Interfaces == Traits ?

Daniel Bonniot <[email protected]>
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
>IMO using the keyword "interface" for what we have in Nice is a
>confusion that will be difficult to overcome by documentation. 
>There's just too much baggage: "Interfaces on the other hand, are pure
>protocol. Interfaces never define data types, and never provide a
>default implementation of the methods".
>
>The Nice interface seems more like what has become known as a Trait. 
>  
>
I'm not sure the term "trait" is well known outside of the circle of 
language researchers (like you ;-), nor that it conveys an evident 
meaning. So most people would have to learn what a trait is and to keep 
remembering using it instead of interface.

On the other hand, it is not hard to explain that among the advantages 
of multi-methods (declaring new methods on existing classes, 
specializing on all arguments) there is also the ability to implement a 
method for an interface. Simple, no?

I would find it awkward to change the name of interfaces just because of 
this fact, because it has nothing to do with interfaces themselves, it 
has to do with the flexibility of multi-methods.

>>Note that you might simply start with:
>>  interface Describable {
>>    IDescTy desc();
>>  }
>>
>>  interface TIntRead  extends Describable { ... }
>>  interface TIntWrite extends Describable { ... }
>>
>>Then you have only one desc() method. Is this not an acceptable 
>>solution? 
>>    
>>
>
>My guess is that we'd soon have a lot of interfaces with only one method.
>  
>
Yes, we would need to see more practical examples. A priori, I would 
think that having the Describable interface is useful. For one, it 
allows to declare desc() only once. So you can share the javadoc 
comments, the contract and the type, which you are duplicating otherwise.

Interestingly, this question is very similar to the alternative 
structural typing/named typing. With structural typing (in ML for 
instance) you build records, and if two happen to have the same set of 
labels they are considered of the same type. On the other hand, with 
named typing (as in Java/Nice), you declare explicitely class names (and 
subtyping with "extends"). The first one is more flexible, the second 
more explicit and safer (no accidental assimilation of two completely 
unrelated features with the same name).

Here, Java considers that since the two methods happens to have the same 
interface, the implementation must be for both, while in Nice you need 
to design you hierarchy to make the sharing explicit.

Daniel



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.