Future of smalltalk (was Re: election details *PLEASE READ*)

Lex Spoon lex at lexspoon.org
Fri Mar 2 22:27:20 UTC 2007


Andreas Raab <andreas.raab at gmx.de> writes:
> J J wrote:
> > Touches on a bit?  Java interfaces are nothing more then c++ base
> > classes that have virtual methods that deriving classes must
> > implement.  Traits is already better then this by at least allowing
> > you to specify what the default code implementation is.
> 
> So you have used traits? In which project? Can I see the code? I've
> been constantly on the lookout for good examples of traits use but so
> far I have only found a few toy academic projects that look beautiful
> (and go and scale nowhere) and one realistic real-world use (the
> traits implementation itself) which to me is a bunch of spaghetti code
> and where I am very curious how maintenance will work out over the
> next years.


Wasn't there a big collections refactoring done with traits?  I have
been meaning to dig it up and read through it, but have never found
the time.

Here's one use of them, though, that I use all the time in Scala's
variation on traits.  You can make Squeak's Magnitude be a trait
instead of an abstract class.  That is, given a < method, which is
abstract in Magnitude, you can have Magnitude define all the other
methods for you.

Or closer to your heart, Andreas, how would you like to have a
Rectangular trait for all those #left, #right, #topLeft, etc. methods?
It would require a #rectangle method, which for Rectangle is "yourself"
and for Morph is "bounds".  Then all these helper methods
would get defined for you by the trait.

This usage of traits may be small one by one, but they are enough to
convince me thre are some very nice uses of traits that are not
available in Smalltalk.  What they do is take a thin interface and
widen it to a rich interface.  They let you *define* classes using the
thin interface, and *use* them with the rich interface.

Anyway, I don't know anything about the Squeak version.  My day jobs
have kept me too busy to look into Squeak's traits as I would like to.
However, I can vouch for the feature, just based on the above
examples.


-Lex




More information about the Squeak-dev mailing list