Aspect? Advice? Joinpoint? Pointcut? Really?
As far as I've been able to understand, AoP is just hooks. You can hook something before or after a function, or 'around' it which is a combination of both. Super useful, but really not that amazing or novel. Definitely does not warrant its treatment as some kind of separate type of programming.
...
Small nitpick with the article: In the example given, the call timing uses 'around', which measures the entire function as opposed to just the part of it that the initial function was measuring, right?
Yes, that's a valid perspective. But it's an incomplete one. Your reduction of AOP is highlighting the mechanism (hooks) but ignoring the purpose (the SOC separation of concerns).
It is the goal/purpose that motivates the separate umbrella label of "AOP". The hooks happen to be one implementation detail.
I'm also not a fan of creating a barrage of neologisms (e.g. see Thomas Friedman books) but the thinking behind AOP generating its own terminology seems reasonable when compared to other concepts if we mentally separate the "hooks" from the "goal":
hooks: insert instrumentation before & after lines of code
goal: performance statistics and optimization
hooks: insert code to mark memory regions with setinels
goal: memory safety check -- detect buffer overruns and wild pointers
hooks: extern "C" ABI, or Win32 COM, or Wordpress plugin specification
goal: extend software functionality by heterogeneous programming languages, or 3rd party developers
With those examples, reducing "goal" concepts down to hooks such as "3rd-party software plugins are just hooks", and "performance instrumentation are just hooks" isn't adding information to why programmers are doing it and also doesn't explain why separate tools are created to support it. Therefore, unifying (reducing) a dozen disparate computer science concepts down to "hooks" isn't going to help us.
Getting past the "hooks" component and focusing on the larger concept (goal) in a systematic way may let us make advancements in its use (tooling, business ROI to implement, etc.)
But I agree in spirit.
Whether this extra descriptive capability is a positive thing is an open question (well, considering AOSD (Aspect-Oriented Software Developement) confernce changed to Modularity, maybe the question has been answered negatively)
I could see wider adoption for a variant of AOP where the join points needed to be explicitly annotated in the code. However, this would just seem to be first-class language support/syntactic sugar for dependency injection/IoC.
There may well be great use cases for AOP, but people need to see examples that justify overcoming the unfamiliarity of AOP. Logging by itself hasn't been a compelling enough use case, and several of the other use cases are almost as well served by dependency injection/IoC without introducing the cognitive load of an unfamiliar programming paradigm.
Also, presumably the cognitive load of AOP goes down with familiarity, but how much does the cognitive load really go down? It seems very difficult to reason about code being arbitrarily inserted at arbitrarily defined join points, without the join points being annotated in the code.
Are there editors with really good AOP support, so that when programming in the large, programmers can easily see the active join points in their programs and expand them? Without good editor support, AOP seems (at least from my shallow understanding) to be a feature that's very useful in the small, but very easy to over-use in the large.
First, the method being given the aspect should be annotated. @LogsArgs or @Transactional. None of this 'oh we just use an auto proxy to apply this to every method' bullshit. Tell me you're doing something.
Second, the annotation should be and to tell you exactly what it's doing with just the name. @LogRequestAndResponse. What does it do? Exactly what it says. If you can't describe the end result easily, then how will the next guy have a clue what just happened?
Whenever I've followed these, I don't regret aspects very often. When I stop following them, people get confused.
Though one wonders if they could get rid of even this if they just had some dynamic scoping.
Uhm...no. I don't really get how someone could convolute declarative rule-based programming with AOP. Granted, they both deal with modularization (aka separation of concerns), but almost all work in PL does! There is a good reason why the AOSD conference was renamed Modularity.
I loathe the day when AOP comes back in style as a 2nd-run fad.
The difference relevant here between the two is that CSS applies its rules over data, and AOP applies its rules over code. (another big difference ofc is that CSS is a DSL whereas AOP is a general purpose technique)
AOP is not generally described as being limited to rule-based techniques.
I fully admit that it may be too much power for mine (and colleagues) small brains, but has anyone ever actually seen AOP work, in practice?
It sometimes reduces coding efforts, but it is the living embodiment of the saying, "If you're as smart as you can be when you write it, how will you ever debug it?"
It's just too much magic spread over too wide an area. I'd much rather have more explicit patterns being used that people can understand, find, reason about, and debug - code reuse is a means to an end, not the end itself.
Again, maybe I'm just not enlightened enough.
I.E, if you insist on catching exceptions in your crosscuts, don't go trying to fix the exception by modifying state. Either kill the thread, or let the original logic deal with it.
Our project was a bit of a laboratory environment. It was a university course that meant to test our ability to apply Patterns of Software Development (i.e. GoF) by having us implement a board game called Bohnanza (basically a heavily simplified Magic: The Gathering).
Our approach was to fully focus on implementing the business logic in a correct and test-driven fashion. In the weeks we spent on implementing the business logic we never implemented any GUI.
Then when it was done instead of polluting the business logic with the traditional MVC architecture, we designed a GUI that was layered on top of the business logic through AOP.
The GUI was just observing through cross cuts the transitions of the games state machine, rendering the relevant game elements and making available the valid inputs. We were one of the few teams who managed to have both a correct game logic and a fully functioning GUI as well as a test suite with good coverage.
Terminology had nothing to do with the issue, in my particular experience.
AOP is an idea that sounds wonderful as a concept - "Hey wouldn't you love not to be peppering your code with logic unrelated to the business logic in your code?"
Great idea...however, every implementation I have seen is terrible. It makes code nearly impossible to test and audit and, in addition, creates a whole other set of code that needs to be tested and audited.
Taking the example at hand. From the first function I have a clear idea of what to expect, when I should see logging and what the failure cases and responses are.
Now instead of a 1 line log statement, the article proposes the 7 line meld definition is much cleaner. Where does this code live?
Another 7 lines to track the length of the call, opposed to 3 lines in the function. And now I have a hidden entry to my function - before the calling path was clear...calling dial() meant I called dial() now calling dial() means I actually call some random function which, assuming it has been written correctly, calls dial()
The error handling is possibly the one redemption here, but still - OO provides you with the tools to encapsulate retry logic just fine without resorting to AOP.
I didn't like AOP when I first came across it at University, I didn't like it when I came across some code at a previous employer, and I don't like it now.
Nice write up though.
No, fortunately. AOP was relegated to the museum of programming history, section 'ideas that didn't work out' (the largest section in the museum, BTW).
> I didn't like AOP when I first came across it at University, I didn't like it when I came across some code at a previous employer, and I don't like it now.
Amen.
We do the same thing in OOP (without the "spooky action from distance" you've noticed) with the Decorator & Strategy patterns, very simple patterns, even those who don't know about patterns are probably using them without knowing.
Essentially, your business logic operations return a function of Implementation => Result, rather than just your Result, and you then call the function with whatever implementation you need at the edges of your application.
But you can also make a feature cross dimensional by using partial classes. So if you want to add a new feature, let's say Move you add a behaviour class in the feature dimension, in a new folder, which implements interfaces from the system dimension like Igui and Igamestate and uses a TroopDataClass from the data dimension. Then you make a new folder in the data dimension and make a partial class for TroopDataClass where you add move based data like petrol. Now that whole feature is isolated, you can easily remove both Move folders and nothing will break everything will compile just as before.
The advantage is that you get rid of the spiderweb dependencies you get if Move where a standard class with combined data and behaviour. For data that still is feature crosscutting like ActionPoint or Position on the map, you can still use inheritance and standard oo techniques within the Data dimension, so TroopDataClass inherits from MapObjectClass or something similar, then all features will have access to them.
http://www.cs.bilkent.edu.tr/~bedir/CS586-AOSD/Syllabus/NDeg...
> Remember that AOP aims to separate concerns from business logic ... It turns out that nearly half our function code is devoted to concerns!
Separation of concerns is about separating concerns from each other, not from business logic. Business logic and logging are both concerns.
It doesn't ruin the article or anything, it's just an interesting mistake.
As long as the logging logic itself is kept elsewhere, having logging instructions within the code is not an obstruction. Logging events themselves can have semantic value, as they would often mark some key point in the execution.
I haven't quite dug into a "real" macro system (I don't mean the c macro system) but is it that a good macro system is able to replace("emulate") AOP?