[Edu-sig] guide to learning decorators
matthewharrison at gmail.com
Mon Jul 9 07:03:17 CEST 2012
Author of said book replying :)
On Sun, Jul 8, 2012 at 10:39 PM, kirby urner <kirby.urner at gmail.com> wrote:
> I got the Kindle book on Python decorators.
> Quite inexpensive.
Yep, that might change as I'm in the middle of revamping my books.
> I didn't give it my highest rating though, for two reasons:
> (a) there's some representing that an exhaustive treatment of the
> function arguments and parameters topic, but the use of * (asterisk)
> on its own, to section off keyword-only parameters, is not mentioned
I'm not sure I'm parsing this correctly. Could you elaborate?
> (b) the authors hint at the many useful and wonderful things decorators
> might do, but are somewhat shy on examples. One would think just
> a few more pages of clever examples would round out the treatment.
Yep, this is a common complaint, and one that I'm addressing in the revamp.
> Other than those two omissions, I thought it was pretty strong. The main
> goal was to get to where your decorator function might itself take
> what that means.
> There are no examples of using a class as a decorator that I recall, nor
> of decorating a class. I should double check that.
You are correct. That is an omission that is somewhat on purpose. To have
properly behaving decorators using classes requires understanding of
descriptors. So it would complicate the book a bit. As people already cower
when they hear decorators, I wanted to have a method that was approachable
and worked reliably. Using classes as decorators is more grokable in some's
opinion. But not reliable.
I'm of the opinion that closures are useful and understandable on their own
and that once they are understood, decorators fall out quite easily. And if
closures make sense, then parameterized decorators are pretty easy as well.
As decorator blog posts pop up quite often I like to keep abreast of this
stuff. It seems to be a topic that interests many Python developers. I've
used this method of teaching closures first to great success at my PyCon
tutorials and have gotten good feedback.
Part of my revamping is to include my iterator/generator book, decorator
book, and a forthcoming book on functional programming constructs and list
comprehensions/generator expressions in a larger tome. I'll probably
include descriptors and classes as decorators in that. I'd love feedback
from anyone on this list, and would get them a review/beta copy in return.
thanks again for the review!
> Edu-sig mailing list
> Edu-sig at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Edu-sig