Are decorators really that different from metaclasses...
Paul Morrow
pm_mon at yahoo.com
Tue Aug 24 12:29:38 EDT 2004
...that they warrant an entirely new syntax? It seems that they are
very similar in a very significant way --- they alter the default
behavior of something. IMO, it's not a stretch to say that they
'parallel' metaclasses; that they are to functions/methods what
metaclasses are to classes. So why don't they share a similar syntax?
class Foo:
""" This is the docstring for class Foo. """
__metaclass__ = M
# body of class goes here
def baz():
""" This is the docstring for function baz. """
__features__ = synchronized, memoized
# body of function goes here.
I personally find the above baz function aesthetically appealing. Does
anyone else feel this way? For contrast, below is the same function
written in the proposed A1 and J2 [*] syntaxes (respectively).
@synchronized
@memoized
@doc(""" This is the docstring for function baz. """)
def baz():
# body of function goes here.
decorate:
""" This is the docstring for function baz. """
synchronized
memoized
def baz():
# body of function goes here.
* if J2 is accepted, the name 'decorate' may be replaced with some other
keyword, but I believe that the structure of the syntax would stay the same.
Paul
More information about the Python-list
mailing list