I recently read an interesting blog post on Anders Hejlsberg’s arguments against AOP.
The first anti-anti argument mentions data binding:
Myth 1. “Aspect-oriented programming is interesting for debugging and instrumentation of code and is not a full-fledged programming discipline.”
Truth 1. Anders probably stopped at the “Hello, world” example.
Although code instrumentation is certainly an important use case of AOP – and the one you would see in every “getting started” documentation – the technology significantly simplifies the work of developers when it comes to implement any non-trivial, real-life application. Just to cite a few real-life scenarios where AOP really helps:
* Data Binding (INotifyPropertyChanged)
I’m trying to think of how AOP is used in a data binding scenario. I always assumed that binding relied on reflection to do it’s "magic." I’m pretty sure everything you need in a binding scenario is available via reflection. Is AOP being used for a (slight) performance boost?
It’s not the databinding he’s referring to, but the
INotifyPropertyChanged(and similar) part that AOP would really shine.Currently, when a class implements
INotifyPropertyChanged, properties look like this:Where with decent AOP, they could look like this
Makes a big readability difference, especially when the setter for a couple properties has a few actual rules in it.
Even with generic base classes, Expressions, Reflection, and some tricky implementations, the best you hope for is:
And even that’s not as readable (and is less performant as well)