Navigating traits in 3.9

Adrian Lienhard adi at
Sun Oct 22 17:41:48 UTC 2006

Hi Andreas,

> Seriously, there is something really wrong here.

Yes, and I even know what is wrong!

The biggest problem is the lack of a good UI. Some work has been done  
by Daniel and few other people; very basic support is provided by  
OmniBrowser as I mentioned in the mail to Tim. I didn't put much of  
my work into the UI but tried to make the traits integration as  
smooth as possible, i.e., to make all other parts of the system work.  
Now, the tools support would need some effort to make traits really  
nice to work with. But you know, its open-source... ;)

Anyway, lets go through your problems step by step:


>  In response to a message that talked about traits and Java  
> interfaces I was looking at TAccessingMethodDictDescription to find  
> out what the rough percentage of "provided" and "required" method is.

The extended Traits OmniBrowser (see TraitsOmniBrowser on of Daniel does exactly this. For each trait and  
class it shows you the required methods.

> Doing so I stumbled across #addSelector:withMethod:notifying: and  
> wondered by myself where its short form of #addSelector:withMethod:  
> went. Browsing the senders of the former netted me 9 places to look  
> at among which were four implementors of #addSelector:withMethod:.  
> And so began the tale of the traits...

If you had used the OmniBrowser tools as I suggested in the other  
mail you would see that among the 4 implementers of  
#addSelector:withMethod: there are 3 that do not implement the method  
locally but obtain it from a trait. This leaves us with exactly _one_  
case to look at: TCompilingBehavior.


> Trying to find the users of TAccessingMethodDictDescription leaves  
> us fishing through menus with no success. "class refs" does  
> nothing, so does Cmd-Shift-N

Of course not. There aren't any references to traits in methods --  
just as there are usually no references to abstract classes.
Again, the problem is a missing UI. To get the users of a trait, do  
"TAccessingMethodDictDescription users"

> But wait, there is something odd here. TraitDescription is a  
> subclass of TraitBehavior and TraitBehavior uses TPureBehavior  
> which is composed from TCompilingBehavior. Oh, and ClassDescription  
> is a subclass of Behavior which uses TPureBehavior too? Isn't that  
> just where we started??? Hello? You still with me? No? Didn't think  
> so.

no, I'm not with you anymore -- because I can't see anything odd here!
It's not that complicated, really. Let me explain it.

Firstly, the classes hierarchy is still the same as it has been in  
the last century...

Behavior - ClassDescription - Class/Metaclass

... mainly with changes regarding adding and removing methods and  
managing the composition of traits. Parallel to that we have a very  
similar class hierarchy for traits:

TraitBehavior - TraitDescription - Trait/ClassTrait

Secondly, to share behavior between those two hierarchies we use  
traits. For example, between Behavior and TraitBehavior there is one  
trait named TPureBehavior (in this case it saves us from duplicating  
about 100 methods). The same way the classes further down the  
hierarchy share traits. So, that's pretty straightforward, isn't it?

What's probably adding a lot of confusion is that those traits are  
again decomposed into sub-traits. This wasn't done to avoid code  
duplication but rather as an attempt to factor out methods into  
logical groups. It seems that this just adds unnecessary confusion  
because without good tools the decomposition is not obvious.

So, since we are at it, lets see if removing those extra traits helps  
you... The attached changeset flattens down all sub-traits (not much  
tested, hence use at your own risk) and leaves us with only one trait  
for each pair of classes.

Now, if _this_ does not help you to understand how this all works...



-------------- next part --------------
A non-text attachment was scrubbed...
Name: FlattenDownKernelTraits.1.cs
Type: application/octet-stream
Size: 1944 bytes
Desc: not available
Url :
-------------- next part --------------

More information about the Squeak-dev mailing list