Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

August 03, 2004

Python Decorators

It's all kicking off in blog land - see Ian Bicking and the Effbot on the latest Python language feature, function decorators.

I broadly agree with these two august gentlemen. It doesn't look nice and I'm not sure when I would use it. At first glimpse it doesn't look very Pythonic, so my initial reaction is that we are probably better off without it.

But then again, life was always better a few years ago, wasn't it? Change is bad, the Daily Mail is good ;-)

In the end, it is Guido's language and he can do what he likes with it. Let's see how this works out and then round him up and chastise him if it all goes horribly wrong.

Posted by Andy Todd at August 03, 2004 10:11 PM


You're absolutely right. It doesn't look Pythonic. There's no way any prefix syntax can ever look Pythonic. Python's just not a declarative language. Yet most (not everyone) on python-dev seems to want some kind of prefix declarative notation.

There is a real problem though. It's the "at least it's better than"-feeling. The "@decorator" is sure a lot better than the "[decorator]" prefix notation, and it's more clear and less cluttered than the "def func [decorator]" syntax.

At least we're only at 2.4a2 yet.

Posted by: simon on August 3, 2004 10:44 PM

How about a decorator-block syntax. ( sorry for taking - as indent, but html thinks otherwise in taking space for it )

decorator require_int, staticmethod:
----def foo( a ):pass
----def bar( a, b, c ):pass

Has the advantage that you can decorate a whole lot of functions at once, and it looks rather pythonic.

Posted by: Florian Bösch on August 4, 2004 08:35 AM