> On 13 May 2015, at 10:42, Yuriy Tymchuk <[email protected]> wrote:
>
>>
>> On 13 May 2015, at 09:25, Nicolai Hess <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>
>> 2015-05-12 12:06 GMT+02:00 Yuriy Tymchuk <[email protected]
>> <mailto:[email protected]>>:
>> Hi,
>>
>> I’ve noticed that if you install a trait on a class and a trait defines
>> explicit requirement method, and this method is defined in a super class, it
>> is being looked up during execution through #explicitRequirement method. It
>> was slowing down my execution by almost 20%. Is there a special way to use a
>> Trait to avoid that, or it’s work-in-progress solution?
>>
>> I find this behavior questionable, when did this change? ( I thought self
>> explicitRequirement always signals an error and does not try to find the
>> method in the superclass chain).
>> Anyway, if you want to use the super class method, you can just remove the
>> method from the trait usage.
>>
>> ASuperClass subclass: #MySubclass
>> uses: ATrait - {#theMethodDefinedInSuperclassAndTrait }
>> instanceVariableNames: ''
>> classVariableNames: ''
>> category: ‘'
>
> Good to know, thanks. I don’t know the philosophy behind this case, but from
> my point of view - trait requires a method, and the class has it, it’s just
> that the method is defined higher in the hierarchy.
I agree, this is the behavior I would expect too. From this point of view, the
problem is the 20% slowdown.
A solution would be that traits does not install explicit requirements in their
users if suitable methods are already in their hierarchy.
Then traits needs to listen to method addition/removal announcements to
install/remove the explicit requirement methods in their users accordingly.
Another solution is to never install explicit requirement methods and have a
modified version of doesNotUnderstand: that detect when the missing method is
an explicit requirement.
So we have four solution:
- explicit requirements does not override methods in the hierarchies of the
trait users:
1. current situation: nothing to do but 20% slowdown (but no slowdown
by removing the explicit requirement from the trait composition).
2. automatic installation/removal of explicit requirement in traits
users: adds more complexity in trait installation logic but transparent to user.
3. dynamic detection of explicit requirement in doesNotUnderstand:
slower DNU but still transparent to user.
- explicit requirements always override methods in the hierarchies of the trait
users:
4. explicit resolution by removing overriding explicit requirements
from trait compositions: less magic but maybe confusing for users
I vote for 2 (then 1, 3, 4).
Camille
> Uko
>
>>
>>
>> regards
>> Nicolai
>>
>>
>> Uko