[Tutor] Decorators

Alan Gauld alan.gauld at freenet.co.uk
Tue Apr 11 21:58:10 CEST 2006

> Syntactic sugar *IS* a practical benefit. After all, every language above
> assember is syntactic sugar, and by your definition of no practical use.

Ah, but by that standard even assembler is syntactic sugar, now
where are those hex codes and my keypunch? :-)

By practical use I mean adding function to the language.
I agree decorators add a modicum of readability, but
they also remove a large slice of Python's readability
by introducing more line noise characters to the language,
and that's a really bad feature from my perspective.

As to your list of benefits:

   * Understand that a function has been modified

I'm not sure I see how decorators do that? Can you give
an example to explain what you mean?

   * Make it clear that a function is a staticmethod/classmethod/etc *right 
      the beginning of a function* without having to read the entire body.

Not been an issue, I found the previous explicit statement to
be just as useful.

   * Reduce typing

Never a good reason for introducing features if the feature
introduces line noise in my book! I'd rather type a few more
characters than contend with $@% type crud.

   * Allow hinting of types for integration with tools like PyObjC

Too esoteric for mainstream, if I want to program in ObjC (and I do!)
I'll use ObjC. Its never worth corrupting one language just to integrate
with another (The only exception I've ever been happy with in that
regard is  the asm/endasm directives in C/Pascal/Cobol/Fortran etc)

   * Make it clear when reading the definition of a method/function is
      memoised, traced etc

I use a debugger for that kind of thing.

   * Simplifying augmentation of generators with arbitrary extra
      communications attributes.

Never ventured into this area yet so can't comment.

Alan G

More information about the Tutor mailing list