Forum: Ruby Ruby and AOP

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90ebe8da17aabd36cc30d9f96a530e6f?d=identicon&s=25 James Herdman (Guest)
on 2006-03-31 04:56
(Received via mailing list)
I'm reading "The Pragmattic Programmer" right now and I'm at the part
about orthogonality.  The authors mention AOP and give an example
involving log writing wherein you can "weave in" some AOP ("Aspect
Oriented Programming" for those not in the know) sexiness and log
writing occurs (the converse behaves as you might expect)**.

It seems to me that this behavior is *sort* of like a mixin -- i.e. you
can mix it in for a new behavior.  However, AOP code seems to be
triggered when certain actions happen.

Does this sound roughly correct to those who have AOP experience?  Have
any of you used AOP in your experience, and if so, where has it been
most beneficial?

Thank you,

James H.

** For those interested, yes a Ruby AOP project exists:
http://aspectr.sourceforge.net/
2a0f7bd2c54fbc44329d69555b96f1c5?d=identicon&s=25 Kev Jackson (Guest)
on 2006-03-31 05:45
(Received via mailing list)
James Herdman wrote:

> I'm reading "The Pragmattic Programmer" right now and I'm at the part
> about orthogonality.  The authors mention AOP and give an example
> involving log writing wherein you can "weave in" some AOP ("Aspect
> Oriented Programming" for those not in the know) sexiness and log
> writing occurs (the converse behaves as you might expect)**.
>
It's actually pretty much like this with aspectj (in java land).  I
haven't used anything except vanilla aspectj, the new version is
combined with AspectWorkz and uses @Annotation style java - something
that so far I've not gotten into

> It seems to me that this behavior is *sort* of like a mixin -- i.e.
> you can mix it in for a new behavior.  However, AOP code seems to be
> triggered when certain actions happen.
>
It's not like a mixin in implementation

> Does this sound roughly correct to those who have AOP experience?
> Have any of you used AOP in your experience, and if so, where has it
> been most beneficial?

The proto-typical use case for AOP is logging, indeed the AspectJ team
did a presentation where they demonstrated how much cleaner Apache
Tomcat could be with an AOP approach towards logging - it's quite an
eye-opener how much code can be replaced by a single aspect.  It's all
good in theory, but in practice (again in java land), the tools are
slightly different ajc instead of javac, decding on runtime or loadtime
weaving etc etc.  Basically if you're already bogged down with
frameworks from hell (I'm looking at you JSF), then adding AspectJ/AOP
in can be an extra thing to try and keep straight.

That said, you can achieve some wonderful results.  I added an auditing
feature to a project where all methods that changed the state of data
caused an aspect to fire and to record the persons name/change etc with
a single aspect (>100 lines of Java/AspectJ) - this made the code much
cleaner as we didn't have calls to an audit service before executing the
business logic, we just let the aspect take care of that.  I've also
used it for security/authentication, again ensure the user is logged in
before performing an action - another (relatively) straightforward
aspect.

One thing I've seen but never coded up is using aspects for caching (the
example used JBoss cache and I didn't have the willpower to download yet
another app server just to test something)

So erm, yeah aspects are quite cool, certainly worth looking at for a
set of problems.  IOC sort of stole their thunder and has negated the
press AOP was getting for a while, but now most IOC frameworks use
aspects internally.

Kev
7e6ee7bc26cac7c3f1edce27558ced3d?d=identicon&s=25 Keith Sader (ksader)
on 2006-03-31 06:03
(Received via mailing list)
On 3/30/06, James Herdman <james.herdman@gmail.com> wrote:
> Does this sound roughly correct to those who have AOP experience?  Have
> any of you used AOP in your experience, and if so, where has it been
> most beneficial?
>

Yes, it's like a mixin but on more than a 'class' level.  It's
cross-cutting(to use the jargon) across class hierarchies.

Basically AOP allows a further and different separation of concerns in
a software system.  Think of transactions and security as better uses
of AoP.  An object should be able to participate in a transaction
without ever knowing it's been in one.  Log writing is the 'Hello
World'  of AoP.

I've used AoP for Logging and exception tracing at runtime of working
systems.

Ron Bodkin and Ramnivas Laddad have excellent blogs on AoP.

hth,
2c8df79b2a68a7532af01d8851f7fa2d?d=identicon&s=25 John Lam (Guest)
on 2006-03-31 06:27
(Received via mailing list)
Another distinction is that AspectJ and related technologies use a
"push"
approach to weave aspects into different join-points in the code. In the
case of a mixin, it's more of a "pull" approach where you have to walk
up to
the type that you want to add the mixin functionality to.

I spent a lot of time a few years ago implementing a runtime
aspect-weaving
extension to the CLR - that had a lot of potential - you could weave
code
into the middle of a running system, and then yank it back out when you
were
done. Great for doing things like injecting diagnostic probes into a
corrupted system to perform post-mortem diagnosis.

-John
http://www.iunknown.com


Yes, it's like a mixin but on more than a 'class' level.  It's
90ebe8da17aabd36cc30d9f96a530e6f?d=identicon&s=25 James Herdman (Guest)
on 2006-03-31 07:31
(Received via mailing list)
> So erm, yeah aspects are quite cool, certainly worth looking at for a
> set of problems.  IOC sort of stole their thunder and has negated the
> press AOP was getting for a while, but now most IOC frameworks use
> aspects internally.

Pardon my naivity, but what is IOC?

Thank you,

James H.
F0d821a746f93cece1240d52d3e2617f?d=identicon&s=25 Pierre-Charles David (Guest)
on 2006-03-31 08:29
(Received via mailing list)
On 3/31/06, James Herdman <james.herdman@gmail.com> wrote:
> > So erm, yeah aspects are quite cool, certainly worth looking at for a
> > set of problems.  IOC sort of stole their thunder and has negated the
> > press AOP was getting for a while, but now most IOC frameworks use
> > aspects internally.
>
> Pardon my naivity, but what is IOC?

IOC = Inversion Of Control. See Marting Fowler's article for a good
explanation: http://www.martinfowler.com/articles/injection.html

There are several implementations in Ruby, Needle for example:
http://needle.rubyforge.org/
3f9aa24fedd4991b512755a5d3a8ffad?d=identicon&s=25 Lutz Horn (Guest)
on 2006-03-31 08:29
(Received via mailing list)
Hi,

James Herdman schrieb:
> Pardon my naivity, but what is IOC?

Inversion of Control. Read Martin Fowler's article "Inversion of Control
Containers and the Dependency Injection pattern" at
http://www.martinfowler.com/articles/injection.html

Lutz
This topic is locked and can not be replied to.