isKindOf: vs. isClassX methods

Dan Rozenfarb drozenfarb at mail.calipso.com.ar
Wed Oct 10 20:52:03 UTC 2001


IMHO the concept of 'type' is independent (although related) to the concept
of class.  It has more to do with the object accepting certain protocol than
with being instance to a certain class or superclass.
For this reason, I rather use methods such as isColor or isMorph because
they allow me to have objects returning the same result even if they don't
share a common superclass (other than Object, of course)

Regards
Dan Rozenfarb

-----Mensaje original-----
De: squeak-dev-admin at lists.squeakfoundation.org
[mailto:squeak-dev-admin at lists.squeakfoundation.org]En nombre de Eddie
Cottongim
Enviado el: Miércoles, 10 de Octubre de 2001 05:41 p.m.
Para: squeak-dev at lists.squeakfoundation.org
Asunto: isKindOf: vs. isClassX methods


I've noticed in many places in the image there are methods such as isColor
or isMorph that identify the 'type' of an object. (See: Object category
testing, Morph category classification). I always thought that this kind of
test was done with "isKindOf:".

isClassX method
pros: allows you to identify the 'type' of an object arbitrarily (not
strictly from the inheritance tree), faster
cons: clutter, possibly encourages a programming style that wants a
too-specific kind of object (this argument seem weaker the more I think
about it-any construct can be used poorly if you try hard enough)

isKindOf:
pros: more general & uniform
cons: slower

"Simple speed test which may or may not characterize average case usage:"
m := EllipseMorph new.
Time millisecondsToRun: [ 100000 timesRepeat: [m isHandMorph] ] 60 ms
Time millisecondsToRun: [ 100000 timesRepeat: [m isKindOf: HandMorph] ] 351
ms

Another way to look at it, isClassX puts the burden of type identification
on the object being questioned, isKindOf puts it on the object that wants to
know.

I've always stuck with isKindOf in my work beacuse I thought it was the
"right thing" to do. I'm guessing that the testing methods in Object, Morph
etc are there for speed reasons. So, as a programmer, I should start with
isKindOf and create explicit methods if isKindOf is a speed bottlenect. Am I
missing any other considerations ?

Thanks,
Eddie





More information about the Squeak-dev mailing list