AOP use cases

Alexandre Fayolle alf at calvin.fayauffre.org
Fri Apr 16 11:23:01 EDT 2004


Le 16-04-2004, Peter Hansen <peter at engcorp.com> a écrit :
> Will Stuyvesant wrote:
>
>> What are good usage examples?
>
> I would be very interested to hear some real-world and real useful
> use cases for AOP as well.


> (The logging one actually annoys me: the only time I've ever
> wanted such logging was when debugging very complicated problems,
> and since switching to TDD I have never encountered anything
> that even remotely made me consider writing such logging wrappers
> again.)

I agree that TDD helps a lot. However, the logging module can be useful
when 
 * debugging a legacy/3rd party application or library
 * trying to understand the data flow of a 3rd party library

Another "common" use of logilab.aspect is the contract aspect which
enables to specify pre and post conditions for methods as well as class
invariants. Of course, you generally don't need contracts when using TDD,
but when working with a distributed team on complex projects, it can be
a great time saver when diagnosing weird crashes. Especially if some
partners have not yet been test infected. :-)
It is easy to disable contract checking once the project is said to 
be stable enough and goes into production, or to re-enable the checks on 
one offensive module or class if something weird happens. 

Of course, it is possible to do this without AOP, and the flexibility
and introspection abilities of Python make it very easy to achieve, on an 
ad hoc basis. It's just that using an AOP framework can save some typing, 
as well as facilitate non invasive changes to existing code. 

-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org



More information about the Python-list mailing list