[squeak-dev] Re: isKindOf: in Morphic code...
marcel.taeumel
Marcel.Taeumel at hpi.de
Mon Jul 4 21:05:57 UTC 2016
marcel.taeumel wrote
>
> Eliot Miranda-2 wrote
>> On Mon, Jul 4, 2016 at 1:59 PM, Tobias Pape <
>> Das.Linux@
>> > wrote:
>>
>>>
>>> On 04.07.2016, at 22:44, Eliot Miranda <
>> eliot.miranda@
>> > wrote:
>>>
>>> > 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
>>> >
>>> > anyFlapsVisibleIn: aWorld
>>> >
>>> > aWorld submorphsDo:
>>> > [:m| m isFlapTab ifTrue: [^true]].
>>> > ^ false! !
>>> >
>>> > with the emphasis on isFlapTab ;-)
>>>
>>> Well, class testing seems to be a Morphic pattern, given #findA: (alias
>>> #submorphOfClass:)
>>>
>>
>> I don't care. It's *WRONG*. isKindOf: is a _bug_.
>>
>>
>>>
>>> Best regards
>>> -Tobias
>>> PS: Not advocating anything just reporting what I found
>>>
>>
>>
>>
>> --
>> _,,,^..^,,,_
>> best, Eliot
> Hey Eliot,
>
> no, it's not a bug. ;-) Although, there is room for improvement.
> #isFlapTab sounds good. Note that this is not even a critical piece of
> code because is only called if you open a system window, for example.
>
> Try [Flaps anyFlapsVisibleIn: ActiveWorld] bench. It's fast enough. A
> microsecond here, having around 30 windows open. So, you will not notice a
> delay. Still, you're right. We should reduce the usage of #isKindOf:.
>
> Not polluting Object means still polluting Morph.
>
> (Yeah, maybe we should use slower computers to program.)
>
> Checks we should consider to add or use more often if it is already there:
> #isCornerGripMorph
> #isProportionalSplitterMorph
> #isCompiledMethod
> #isColor
> #isInfiniteForm
>
> ... still, a quick look through the usage of #isKindOf: in Morphic code
> revealed no serious performance issues. We should refactor MenuMorph to
> not need #isKindOf: that often. This might also be true for other places.
>
> The pattern "isClass" is not always a good solution for many cases in the
> system.
>
> Best,
> Marcel
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
--
View this message in context: http://forum.world.st/isKindOf-in-Morphic-code-tp4904890p4904897.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.
More information about the Squeak-dev
mailing list
|