Thinking in aspects

AOP may be mainstream, but are people *thinking* in aspects yet?

AOP has proven itself as a very useful technique for centralising the cross-cutting concerns of an application and many of us use aspects in our day to day work, but are people thinking in aspects yet?

For example, frameworks like Spring use aspects under the covers to implement things like support for transactions, but effectively this is all hidden away from the developer. What I'm interested to know is whether people are explicitly designing aspects into their software. Based upon my own experience, I've not seen many instances where this has been done; where developers have made a concious decision to use aspects to solve a particular problem. Are your experiences the same?



Re: Thinking in aspects

Certain classes of problems align well to the AOP approach. An example from my past is a simple performance monitoring tool. I defined a pointcut that measured how long a method took to execute. I used Spring and AspectJ to add this around calls to the business service layer. This allowed basic method timings to be cleanly added without code changes to the api.

This was a textbook example (similar to logging which is often mentioned in AOP discussions) where AOP's cross-cutting approach fits neatly. The functionality applied across a whole logical layer of the application rather than a specific business requirement.

I agree though - finding the areas where aspects fit is tricky. Maybe they are intrinsically more suitable for tackling non-functional requirements. Audit is another strong fit with AOP for example.

Re: Thinking in aspects

yes, my experiences are the same. From long back I thought AOP a misnomer because it doesn't deserve to be classified as an "orientation" in programming. It's useful, but it doesn't radically change the way we organize code.

Re: Thinking in aspects

AOP is hard to explain and therefore hard to sell to managers. At best, they look at it as some unnecessary and complex toy. Junior programmers saying "I don't get it" don't help, either. As a consequence, introducing AOP by example is a lot easier than doing so by design.
The obvious examples to get everyone hooked are logging and performance monitoring: Code and configuration aren't too difficult and they save a lot of time and effort. Pre 2.0 Spring AOP helps by making it transparent how things are working: there's no "magic" involved.
The next step is to point at the ubiquitious gzip-filter and asking them to look at it as an example of AOP in the web layer (well, sort of...).
One area that benefits a lot from AOP is enterprise application integration. E.g., sending an e-mail in case of a certain event leads to clutter in your business code. Put it into in aspect and everything looks much cleaner.
IMO the tricky part for an architect is to get the "go" before having to implement code that really benefits from AOP.

Re: Thinking in aspects

I decided to use aspects to implement caching on the webapp I'm working on. It works really nicely when it works but it's practically impossible for junior developers to debug.

I was looking for other areas where AOP might be appropriate but there really wasn't much more. To be honest the web app is a fairly straight-forward, simple web application, so maybe it's not a surprise that AOP isn't really necessary. On the other hand it's an example of exactly the sort of app we find everywhere, so maybe AOP isn't something that is essential to every-day programming.

Re: Thinking in aspects

AOP as a concept is a great idea. Unfortunatelly current implementations make it difficult to use. Spring implementation for instance is very buggy. When you debug, stack trace grows to unbeareble sizes. Runtime weaving is great but again makes startup slow and adds complexity. Guice usage of AOP seems to be the most elegant but limited. I guess if AOP support was native to JVM it would improve the situation.

Add a comment Send a TrackBack