[squeak-dev] Traits as a way of defining an interface instead of an abstract superclass

Chris Cunnington smalltalktelevision at gmail.com
Fri Oct 12 16:21:38 UTC 2012


I've been looking at MetaObjects's [1] decade old implementation of the 
vm in Cocoa. It has a class called SqueakInterpreter.h that defines a 
protocol that is used in SqView. The selectors are listed in 
SqueakInterpreter.h but implemented in SqView.m. I believe this kind of 
thing is now called a category in Objective-C-ese. And I was wondering 
why somebody would do this? We don't separate the protocols from the 
classes in Smalltalk. And I think the reason is we use abstract 
superclasses. And we have deep user developed hierarchies.

Then it occurred to me that Objective-C doesn't have any user 
hierarchies of any depth. There are framework hierarchies of great 
depth. But the programmer in Objective-C from the start is supposed to 
go straight to composition and only produce very shallow hierarchies. 
I've got a book where a designer of Objective-C says inheritance is 
superfluous.[2]

OK. Composition good. Inheritance bad. And it explains why there is no 
decent hierarchy browser in Xcode 4. There was one in Xcode 3 and they 
tossed it.

And following these protocols from where they are defined to where they 
are implemented and where all developer hierarchies are two classes deep 
feels sort of like walking around a basement where the ceiling is too 
low with a flashlight looking for a crate.

And so I'm guessing that this idea of splitting a protocol from its 
class has bled into Squeak from Objective-C in the form of Traits. 
Casimiro must have a reason for using them that he likes. But they do 
seem like a workaround as a result of a shallow hierarchy. I think I'd 
rather create my own abstract superclass to define an interface.

Chris


[1] http://www.metaobject.com/downloads/Squeak/

[2] "Masterminds Of Programming" (2009) O'Reilly, pg. 258-260. Brad Cox 
quotes:

"Inheritance just isn't all that important. Encapsulation is OOP's 
lasting contribution."

"Smalltalk didn't have anything like protocol in those days and that was 
added by Steve Naroff, who is now in charge of the Objective-C at Apple."

"At first I used inheritance heavily, experimenting to find its bounds. 
Then I realized that encapsulation was the real contribution of OOP and 
that it could be used manually to do almost everything I'd been using 
inheritance for, but more cleanly."




More information about the Squeak-dev mailing list