[squeak-dev] Re: isKindOf: in Morphic code...

Phil (list) pbpublist at gmail.com
Mon Jul 4 22:39:33 UTC 2016


Mercel,

On Mon, 2016-07-04 at 14:05 -0700, marcel.taeumel wrote:
> > > > > 

<snip>

> > > > > Hi All, Hi Marcel,
> > > > > 
> > > > >     when I see code like this, and there's a lot of it in
> > > > > Morphic,
> > > > > 
> > > > > !Flaps class methodsFor: 'testing' stamp: 'mt 5/17/2016
> > > > > 14:17'!
> > > > > anyFlapsVisibleIn: aWorld
> > > > > 
> > > > >         aWorld submorphsDo: [:m |
> > > > >                 (m isKindOf: FlapTab) ifTrue: [^ true]].
> > > > > 
> > > > >         ^ false! !
> > > > > 
> > > > > I think this is performance thrown on the floor (isKindOf: is
> > > > > awfully
> > > > slow, especially in huge hierarchies like Morphic, and bad
> > > > design,
> > > > restricting one to a concrete class).  And I think that Morph
> > > > provides a
> > > > perfect place to put an extension that doesn't pollute
> > > > Object.  So I
> > > > would
> > > > like to see
> Okay, here is some more constructive feedback on this issue.
> 
> The problem is that there are morphs in the world that do not want to
> be
> covered: flaps, docking bars, etc. So, it would be good to attach a
> property
> to that morph that says "please do not cover me". Then the
> RealEstateAgent
> just has to iterate of a world's submorphs once, check for that
> property and
> some bounds and we are fine.
> 
> No need for #isKindOf:.
> No need for #isFlapTab.
> 
> Right now, the algorithm is even broken because we assume that all
> flaps
> have the same size. For example, there cannot be a bigger icon, a
> smaller
> text, or whatever. They all have to have the same size. Kind of
> unnecessary
> limitation.
> 
> This is the actual "bug".
> 
> Best,
> Marcel
> 

It's great that you've eliminated the usage in this specific example
but you are not seeing the forest for the trees.  Eliot's comment
wasn't concerned with what was being tested or why it was being tested,
but rather how it was being tested.  #isKindOf: is testing what exact
kind of thing something is, and its performance implications, rather
than how the thing you are testing behaves.  So if someone were to come
along with MyBetterFlapTab in an alternate class hierarchy, the test as
it current stands will not only perform sub-optimally, but it also
won't behave as expected (i.e. if MyBetterFlapTab implements the
FlapTab protocols it is reasonable to expect an instance of it to work
wherever an instance of FlapTab does)

I think what Eliot was asking was that wherever such tests are being
performed, and for whatever reason, to not use #isKindOf: and use a
protocol-based #is* approach instead that doesn't look at the concrete
class.  Re: the concern about polluting Object, Morph, or whatever...
perhaps using a more generalized #is: approach could help.  Or if it is
such a specialized (i.e. one-off) test that an #is* or #is: check would
not make sense, there is always #respondsTo:

Thanks,
Phil


More information about the Squeak-dev mailing list