Runtime Traits?

Andreas Raab andreas.raab at
Mon May 30 20:01:06 UTC 2005

Hi Mike,

The only (forgivable) ignorance on your behalf is in making the 
distinction between compile time and runtime. There is no such thing in 
the 21st century. It is perfectly possible, well-motivated, and indeed 
likely to be trivial to add traits at runtime. You might have to create 
a new class for making this work but then again, this can happen at 
runtime (the eToy system uses this extensively to give you a 
prototype-feel in the environment). If you dig around just a little 
you'll probably find the messages that are needed to add traits dynamically.

And yes, you should be a little concerned. You have all the means you 
need to shoot yourself in the foot in entirely new and unforeseen ways. 
But hey, you asked for it, didn't you? ;-)

   - Andreas

Mike wrote:
> Hi all, please forgive me if this betrays a terrible level of 
> ignorance on my part, but I think there is benefit to be had in 
> runtime traits injection, to coin a phrase.  I am writing software 
> to enable back testing of stock trading strategies.  Each strategy 
> makes use of a selection of technical indicators, and each 
> strategies combination of stratgies is usually different.  I am 
> writing the technical indicators as traits, which layer over a 
> simple Tick class that has open, high, low, close and volume 
> accessors to represent the stock data.  I would prefer to inject 
> the relevant traits as required by the individual strategy, 
> instead of rolling all the traits into one class.
> I'd just like to know what others think of traits being a compile 
> time thing.  And whether there might be value in mixing them in at 
> runtime.  I am also dimly aware of the potential for there being 
> little different between compile time and runtime in smalltalk.
> Thanks for listening.
> Mike.
> ------------------------------------------------------------------------

More information about the Squeak-dev mailing list