[PEAK] Re: Persistence styles, MDA, AOP, PyProtocols, and
PEAK
Phillip J. Eby
pje at telecommunity.com
Sat Aug 7 12:12:10 EDT 2004
At 04:48 PM 8/7/04 +0100, Paul Moore wrote:
>Paul Moore <pf_moore at yahoo.co.uk> writes:
>
> > "Phillip J. Eby" <pje at telecommunity.com> writes:
>
> >> I'm speaking here of "multiple dispatch". More specifically, I'm
> >> talking about a kind of symmetric multi-dispatch that's closer in
> >> nature to the kind found in the Cecil and Dylan programming languages
> >> than what's in CLOS, but the basic idea is the same.
>[...]
> > Woo hoo. Not only a nice idea, but available now? Off to look at
> > PyProtocols CVS...
>
>Given the latest state of the decorators debate, what are your
>thoughts on the list-before-def hack implemented in PyProtocols?
That I'll be keeping it around, and as soon as I support Python 2.4, I'll
try to find a way to support when as both an '@' decorator and a
list-before-def decorator. This should be quite possible, albeit tedious,
to do.
Basically, 'when' and other decorators of their ilk will need to return a
function that can be called to do the decoration in place of the
trace-based advisor, that will also *disable* the trace advisor if the
function is called.
>Clearly (I guess) users of Python 2.4 will be able to use "real"
>decorators, albeit at the expense of not being backward-compatible.
>Assuming that they do, will there be a cost for the mere existence of
>the list-before-def hack? Maybe the list-before-def compatibility
>syntax needs to be moved to a separate module, so that people who
>don't need it don't pay a cost.
>
>Or maybe there isn't a cost... But I recall mention of a trace hook
>being involved - doesn't that execute code at least once per scope
>entry?
The trace hook is installed when you invoke the decorator, and uninstalled
when the next assignment in that scope occurs. So, the performance penalty
doesn't continue beyond that point. So, for example in:
[when("something")]
def foo(bar):
...
The trace lasts from the first line until just after the 'def'. In effect,
it hardly lasts at all, unless you have multiple decorators. As soon as
the trace hook detects that there has been an assignment (i.e. 'foo' is
bound to the function object), it does its thing and uninstalls itself.
Have a look at 'protocols.advice.add_assignment_advisor' for more details.
FWIW, I would like to add some additional function decorators in
PyProtocols 1.0, to make it easier to declare a function as an adapter
factory, or to declare that a function implements an interface. As with
'when' and its ilk, they will also be made "forward-compatible" to 2.4 at
some point.
More information about the PEAK
mailing list