3
votes

Aspect Oriented Programming (AOP) seems like an interesting concept. At first I was pretty enthusiastic about it, but as I read more and saw the use cases people were describing I grew disappointed.

A lot of sites I saw, plus a presentation from the developers of AspectC++, presented use cases that I found rather dubious.

They talked about how AOP can be used to do error handling (throwing exceptions), do bounds checking on parameters and return values, return safe null objects in case something goes wrong, security, etc. Are these just bad examples (and not actual use cases), or am I missing something?

How are you supposed to be aware of what's happening when you call a function? Virtually anything can happen, depending on what aspects you decide to apply. Isn't that going to mess up things really really badly? What about API documentation, how am I supposed to write that?

So far the only good use cases for AOP I've seen are things like logging or profiling — things that don't influence the actual logic flow and serve only as debugging tools.

Is AOP useful for anything else other than debugging mechanisms?

1
possible duplicate of Do you use AOP? and what for?Matt Ball
I think Do you use AOP? and what for? is more about example uses and this seems a bit more about theory and effects on code quality.Jared

1 Answers

4
votes

AOP is most useful when you have concerns that aren't relevant to the main concern of your application (called orthogonal concerns). It can be super handy when you have to add a concern to existing code (say security to something that was built for internal private use) or have to add functionality that for whatever reason just doesn't fit into your domain model without really obscuring your business logic.

I wouldn't use it anywhere you have to wonder what is happening when you call a function. That seems like code smell to me.