My proposed talk for PyOhio
Here’s what I submitted for a presentation topic for PyOhio:
TITLE: Decorators are fun
EXPERTISE LEVEL: Hopefully, there will be something for everyone. Novices might enjoy the material at the beginning mostly, while experts would likely be more interested in the ruledispatch discussion.
SUMMARY: This talk will start with a friendly walkthrough of decorators for people that have never seen them, then go into some straightforward examples, then finish with a review of how decorators are used in Philip Eby’s ruledispatch package.
OUTLINE:
- The simplest possible decorator.
- Pass arguments to a decorator.
- Write a decorator and still preserve the function signature of the decorated function.
- Coerce values into a function into types using decorators.
- Log values coming out of a function.
- Phillip Eby’s ruledispatch package implements generic functions, aka multimethods, for python. I’ll walk through how he uses decorators, and why they’re such a good idea for this.
Rick Harding said,
May 19, 2008 @ 1:44 pm
Sounds cool. I’m psyched to see this event going down and hope this gets in there.
Kevin Dangoor said,
May 19, 2008 @ 3:42 pm
Sounds like a good talk topic!
As someone who’s written more than my fair share of decorators, can I also suggest mentioning some of the pitfalls (like argument introspection might not work the way it did pre-decoration, and that order of decorators can make a difference).
Paver and TurboGears 2 use the decorator syntax to keep track of behavior that you want applied without being true “decorators”. I believe TG2 uses *a* decorator and the rest just keep track of how you want things to behave. Paver’s decorators do not actually alter the function at all.
matt said,
May 19, 2008 @ 3:46 pm
Hi Kevin — thanks for the idea to talk about the pitfalls. I think I will add a section for that (if I get picked).
I’ll have to study how pavers uses decorators without altering the function. Sounds like a neat idea. I’m speculating that the decorator alters some other data structure.
Phillip J. Eby said,
May 21, 2008 @ 11:49 am
FYI, you might also want to look at DecoratorTools (which is used by RuleDispatch to implement its decorators) and PEAK-Rules (which is a modern replacement for RuleDispatch, also based on DecoratorTools).
matt said,
May 21, 2008 @ 11:51 am
Hi Phillip — I’ll look at those packages. Thanks for the tips!