On Wed, 19 Oct 2005, Christophe Grandsire wrote:
> I find it a great idea to use modules for cuts to. A genial way to minimise the
> amount of new features to implement and learn!
Thank you for the kind words!
> So I don't have to worry that subclasses would suddenly behave differently from
> their parents without explicit overriding. Cool.
>
> That said, I'm suddenly thinking that sometimes one would rather want to
> subclass the class as it stands without its aspects. If I'm thinking for
> instance of the issue of logging. The way it stands now, if the parent class
> gets a logger cut, the subclass suddenly gets logging functionality *in the
> middle of its overridden methods*, when they use super, whereas one would
> rather expect the logging aspect to be *external* to the implementation of the
> subclass (if it is to be there at all). I hope I'm making myself clear. I have
> difficulties to express my thoughts in words today...
I think I know what you mean. I think this can be done with a bit of
library support. The following should do what you want it to do, and it
can surely be done automatically by a library:
class A
def do_transaction ; ... ; end
end
class B < A
def do_transaction
do_some_stuff
super
end
end
module CutMixin
def do_transaction
do_logging if Thread.current['InsideLogger']
old = Thread.current['ACut::InsideLogger']
Thread.current['ACut::InsideLogger'] = true
super
Thread.current['ACut::InsideLogger'] = old
do_logging if Thread.current['InsideLogger']
end
end
cut ACut < A
include ACutMixin
end
cut BCut< B
include ACutMixin
end
> What do you think? I like the way cuts act in a really transparent way, and that
> when subclassing one needn't know about the existence of cuts, but I'm now
> wondering whether it could be a problem in some cases when the aspect should
> really stay external to the implementation of classes... Do you have a way to
> solve that problem already?
>
>> Note: if you use the patch, the keyword 'cut' is named '__cut__'. This is
>> because the Tk library uses 'cut' as a method name and it fails the tests
>> otherwise.
>>
>
> I hope this small problem won't prevent the RCR to be accepted.
> --
> Christophe Grandsire.
>
> http://rainbow.conlang.free.fr
>
> It takes a straight mind to create a twisted conlang.
Peter