AOP Ruby and Aquarium
 
While attending Dean Wampler presentation at ChiRb the last night I failed to understand the reasons why bringing AOP semantic to dynamically typed language can be a good thing. The reason is simple! I never tried aliasing and evals a big Ruby project :) I had just some Python AOP-like experience in the past using the language meta-programming facilities and it was not such a big pain.
 
Debasish Ghosh explained his reasons why Ruby should have AOP integrated at an higher level than aliasing and I completely agree. The fact that a language supports strong meta-programming means just that building an AOP framework for that language is simpler and probably more powerful than building the same, for example, in Java. Java introduced the Instrumentation interface and related package to allow bytecode manipulation at load-time. This tool can be useful when you want to intercept calls and add behavior to a class the AOP-way. Does this mean that a developer should use Instrumentation directly to apply AOP to his/her applications? The answer is of course “no” because it’s too complex. I agree that bytecode instrumentation is much lower level than Ruby aliases and cannot be considered “meta-programming” but they are two example of enabling tools/technologies for AOP.
 
AOP is an abstraction to encapsulate cross-cutting concerns and their behavior inside an application. If the target language supports strong meta-programming, then implementing those abstractions will be easier but just the presence of the tools doesn’t mean automatically built-in AOP. For this reason, with the actual Ruby language specifications, an high level abstraction AOP effort like Aquarium is more than welcome.
 
Aquarium introduces an AspectJ like support for Ruby. Pointcuts for now are just the basic ones but the framework is still at the beginning. There are for sure two nice things about implementing an AOP framework in Ruby:
  1.  The aspects configuration can be done as an internal DSL, no need to exit the language or to use fancy XML
  2.  The framework implementation can use the strong meta-programming capabilities of Ruby
 
 
Reblog Details
Wednesday, October 3, 2007

free hit counter