On Friday 02 May 2008 16:07:56 John M. Dlugosz wrote:

> chromatic chromatic-at-wgz.org |Perl 6| wrote:

> Why is there any difference in declaring classes and roles if a class
> can be used as the target of either 'is' or 'does'?

You can't instantiate a role.  You can instantiate a class.

When you declare a class, you're collecting behavior and state into a named 
entity.  When you instantiate a class, you create an object with behavior and 
state conforming to that entity.

When you perform type-checking against an object, you're specifying that you 
want something that conforms to a named entity.

If you want polymorphism and genericity, you need a way to specify that -- 
despite the specific current class of an object -- anything which explicitly 
conforms to a named entity -- no matter *how* it does so -- is fine.

There are two important points.

1) Naming collections of behavior and state is fundamental to the type system.

2) How any particular entity *implements* that behavior and state is not 
important, as long as you explicitly declare that conformance through some 
mechanism.

2b) If the only way to declare that conformance is through subclassing, you 
lose and I'll take your language designer license away*.

2c) If you have to edit other people's source code to extract a role from an 
existing class just so that you can declare explicitly that an entity of your 
own devising conforms to that role, you lose, and I'll take your language 
designer license away and salt the earth around your house*+.

That's it.  A class is a specialization of a role in that you can instantiate 
it.  Everything else a role implies, a class implies implicitly.

We are trying to avoid the "java.lang.String is Final" problem here in various 
ways.  One of them is not allowing library designers to mark things as final.  
One of them is by allowing the happy coincidences of ad-hoc polymorphism by 
making polymorphic equivalence cheap and easy.  One of them is by being a 
whole lot smarter and more handsome than the Java designers.

* Note that there is no language designer license.  Yet.

+ I do have salt.

-- c

Reply via email to