Alternative decorator syntax - keyword choice

Jeremy Bowers jerf at jerf.org
Sun Aug 22 02:44:30 EDT 2004


On Sat, 21 Aug 2004 21:51:09 -0700, Robert Brewer wrote:
> I'd be most interested to hear arguments _against_ "declare", if there
> are any.

My first objection would be that decorators aren't "declarations"; that is
one use but not the only one.

The flip side is that I doubt that any one word will ever capture as a
reasonable verb what they are doing, so I'm not sure this argument is
meaningful, as it applies equally to all proposals, up to and including
"decorate". ("Decoration" is the mechanism, but it is not always the
result.)

I'd have to say "transform" is probably the best candidate here; while not
all uses of decorators are transforms (like attaching pieces of metadata),
it at least brings to mind the correct implementation, which is the
passing of the method through a function. 

"declare" brings to mind attaching a piece of data to the function or
making a statement about the function to the compiler, without changing
the underlying function. Ditto "apply".

"decorate" brings either nothing to mind, or some vision of the Design
Pattern which really isn't right.

"as" seems to imply some sort of syntactic change, and only works AFAICS
for staticmethod and classmethod. "as: author('Steve')" doesn't make much
sense.

To sum up, *all* keywords are insufficient, and I think there are only two
choices, depending on the goal: "transform" to give a hint about what is
really happening, or "decorate" on the grounds that there *is* no
ready-made keyword and it is reasonbly easy to attach whatever Pythonic
connotations to the word we choose; witness "generators".


(Apologies if this has been mentioned before; I've been trying to keep up
but I have failed.)



More information about the Python-list mailing list