@decorator syntax is sugar, but for what exactly? (decorator libraries).

Skip Montanaro skip at pobox.com
Wed Aug 11 10:55:32 EDT 2004


    >> Yes (using a class instead of a module simply for convenience):
    ...

    Art> Is it me, or this a chilling argument agaisnt where things are
    Art> going.

I'm not sure what you're getting at.  Nobody said a decorator's
implementation had to be simple.  It can, after all, perform pretty
arbitrary transformations.

    Art> But when there is a lot less going on than meets the eye ...

Again, I'm confused.  Look at just the fib() definition:

    @martha.memoize
    def fib(n):
        assert n >= 0
        print n
        if n <= 1:
            return 1
        return n + fib(n-1)

The decorator says the function will be memoized.  That memoizing an
arbitrary function's values using a dict isn't entirely straightforward
shouldn't prevent people from being able to easily memoize functions whose
outputs only depend on their inputs.  By analogy, I use urllib.urlopen() all
the time without completely understanding all the ins and outs of what it
does.

Perhaps the decorator would be better named "idempotent"?

Or were you objecting to something else?

Skip



More information about the Python-list mailing list