Rather than decorators, how about sections?

Paul Morrow pm_mon at yahoo.com
Wed Aug 11 21:10:22 CEST 2004

Paul McGuire wrote:

> This only addresses the "decoration" for declaring static and class methods.
> The decorator mechanism is intended to include much more than this simple
> class declaration feature.  See
> http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary for the first
> application (memoize - a return value cacheing helper/decorator, to optimize
> access to repetitive or compute-intensive function calls, with NO changes
> needed to the function itself).  Other decorator candidates I've seen
> mentioned are:
> - mutex lock/unlock wrapper
> - debugging/logging wrapper
> - pre-condition/post-condition assertion wrappers
> - input argument validation/typing wrapper
> - return value type validation wrapper > needed to the function itself).

memoize is an example of something that probably should not be specified 
in the method definition.  It's strictly a 'pragma' --- just a 
suggestion to the compiler on how it could speed up the function.  That 
kind of 'decoration' (as well as some of the other examples you cited) 
is of a 2nd class nature in that it doesn't affect whether the program 
produces the correct result or not.  Therefore, I would not want to have 
such statements comingled with the statements that truly are germane to 
the correct functioning of my code.  They would only be a distraction, 
and are best relegated to some other place in the code-base (another 
file perhaps).

That's kindof the thinking behind aspect oriented programming (AOP).  A 
body of code should deal with only one aspect of the problem...

More information about the Python-list mailing list