How about... something completely different? (Re: [squeak-dev] Re: On traits composition)

Göran Krampe goran at
Tue Dec 8 22:24:01 UTC 2009

Hi all!

Andreas Raab wrote:
> BTW, I really don't think there is much difference between mixins and 
> traits; all forms of MI are fairly equivalent.
> Cheers,
>   - Andreas

As most of us I was also very positive when Traits first came to the 
scene. Now, I am a lot more jaded and think "well, sure, but are they 
worth it?".

Given Andreas' statement above - wouldn't it be *much* cooler to evolve 
Smalltalk along the axis of composition instead of the axis of inheritance?

I have always thought that having better mechanisms for delegation would 
be awesome, and would in most ways be much more powerful than 
inheritance (in whichever form).

For example, what if one could declare that for class Foo (having ivars 
x, y, z) any message that would result in a DNU would instead be 
"delegated" to ivar x (and then y if no lookup is found in x either).

This would be equivalent to tons of messages in Foo like:

	^(x respondsTo: #name) ifTrue: [x name] ifFalse: [y name]

(well, kinda, you get the picture - but also, taking care of x/y 
returning "self" in which case we probably should return the "Foo self" 
instead etc)

In many ways the mechanism I am describing is "built into" languages 
like self and Slate (I think).

IMHO the above is very useful and would allow fine grained composition 
similar to Traits but in a dynamic more object centric fashion.

regards, Göran

More information about the Squeak-dev mailing list