@decorator syntax is sugar, but for what exactly?
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Aug 8 06:55:08 CEST 2004
> I have read a few Python blogs and not a one is taking the decorator syntax
> in a good way.
classmethod and staticmethod were introduced some time ago, to provide
a mechanism for getting to such effects. At the time there was no clear
syntax to use that "felt right." In the meantime people have used these
features to good effect despite the clunky way you used them. At this
point there would probably be a small riot (or at least a large whine)
if these two were removed.
When I first came to Python, I was delighted to see that Idle gave me
function clues not only for the system code, but for the code _I_ wrote.
Since it takes discipline to write comments that may never be read, it
was delightful to finally see an immediate reward for doing a little
documentation work -- I could help myself on my own utility functions.
However, there are more and more uses of the docstring for things other
than documentation. At this point, I see more and more docstring uses
as "cybercrud" -- The only easy function annotation is the docstring so
all ambitious program annotation schemes use it. There are good reasons
for wanting to be able to annotate functions and methods, but precious
few good reasons for polluting the document strings in order to do so.
Decorators are a way out. I don't know about the syntax, it looked bad
when I first saw it, but like some others, I welcome _almost_any_syntax_
for decorators. Not, so much, because I want to use decorators. I just
want others to stop using docstrings for non-documentation purposes. In
fact, I don't even really like the unittest convention of using method
names to identify test methods -- I prefer a language where the what you
call a thing does not affect how it works.
> The Python of 1.5.2 simplicity will be long gone.
Well, there was a lot to like even then, but I'd hate to give up what
we now have -- you can do things in a much more functional style now,
with nested scopes. Would you really like to go back to three-strikes
and you are out symbol lookup? This language has changed at a good
pace, and (quite surprisingly) slowly to a more consistent model (a
major coup in language design). The aesthetic that has driven that
change suggests that this might be the right syntax for declarators.
I know I wouldn't have done nearly as well as Guido and gang at making
I certainly intend to take this alpha period as a time to experiment
with decorators and see if the syntax grows on me; I suggest others
do the same. Give it its best chance; you may become a fan. Several
of the py-dev people claim they have already gone from distaste to
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list