TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Introduction to Aspect-Oriented Programming

57 pointsby owlishalmost 11 years ago

12 comments

makmanalpalmost 11 years ago
AoP strikes me as one of those things where someone just invented a bunch of terminology around a really basic concept, for no good reason.<p>Aspect? Advice? Joinpoint? Pointcut? Really?<p>As far as I&#x27;ve been able to understand, AoP is just hooks. You can hook something before or after a function, or &#x27;around&#x27; 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.<p>...<p>Small nitpick with the article: In the example given, the call timing uses &#x27;around&#x27;, which measures the entire function as opposed to just the part of it that the initial function was measuring, right?
评论 #8027148 未加载
评论 #8027138 未加载
评论 #8026654 未加载
评论 #8026791 未加载
评论 #8027110 未加载
评论 #8028657 未加载
sarahjalmost 11 years ago
urggh...is this still a thing?<p>AOP is an idea that sounds wonderful as a concept - &quot;Hey wouldn&#x27;t you love not to be peppering your code with logic unrelated to the business logic in your code?&quot;<p>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.<p>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.<p>Now instead of a 1 line log statement, the article proposes the 7 line meld definition is much cleaner. Where does this code live?<p>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()<p>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.<p>I didn&#x27;t like AOP when I first came across it at University, I didn&#x27;t like it when I came across some code at a previous employer, and I don&#x27;t like it now.<p>Nice write up though.
评论 #8026978 未加载
评论 #8026427 未加载
KMagalmost 11 years ago
Apart from logging, it would be good to see a variety of examples where AOP is clearly preferable to dependency injection&#x2F;IoC. AOP has a bit of a feel of &quot;spooky action at a distance&quot; to it. Extra code is inserted in your code, without you inserting some markers at that point as a clue to the reader.<p>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&#x2F;syntactic sugar for dependency injection&#x2F;IoC.<p>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&#x27;t been a compelling enough use case, and several of the other use cases are almost as well served by dependency injection&#x2F;IoC without introducing the cognitive load of an unfamiliar programming paradigm.<p>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.<p>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&#x27;s very useful in the small, but very easy to over-use in the large.
评论 #8026414 未加载
评论 #8027562 未加载
评论 #8026693 未加载
seanmcdirmidalmost 11 years ago
&gt; Every time you use CSS, you’re doing Aspect-Oriented Programming<p>Uhm...no. I don&#x27;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.<p>I loathe the day when AOP comes back in style as a 2nd-run fad.
评论 #8028696 未加载
评论 #8028222 未加载
hcarvalhoalvesalmost 11 years ago
Could monadic types solve the same problem in codebases, by letting you compose &quot;business&quot; and &quot;implementation&quot; functions?
评论 #8026837 未加载
GarvielLokenalmost 11 years ago
Multi-Dimensional Separation of Concerns is more useful and can easily be modelled in standard oo without tools. In a game for example you can have three dimensions, data, features and system dimensions. Where each is a folder hierarchy in your solution. Here you use the standard oo cross dimension with interfaces. Like system dimension export interface IGUI which exposes return actions and info functions that features and the data dimension classes can implement.<p>But you can also make a feature cross dimensional by using partial classes. So if you want to add a new feature, let&#x27;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.<p>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.<p><a href="http://www.cs.bilkent.edu.tr/~bedir/CS586-AOSD/Syllabus/NDegreesOfSeparation.pdf" rel="nofollow">http:&#x2F;&#x2F;www.cs.bilkent.edu.tr&#x2F;~bedir&#x2F;CS586-AOSD&#x2F;Syllabus&#x2F;NDeg...</a>
评论 #8027176 未加载
dcrealmost 11 years ago
Nice writeup, though I was struck by the author&#x27;s funny use of the word &quot;concerns&quot;:<p>&gt; Remember that AOP aims to separate concerns from business logic ... It turns out that nearly half our function code is devoted to concerns!<p>Separation of concerns is about separating concerns <i>from each other</i>, not from business logic. Business logic and logging are both concerns.<p>It doesn&#x27;t ruin the article or anything, it&#x27;s just an interesting mistake.
michaelcampbellalmost 11 years ago
I&#x27;ve bought into the AOP thing a couple times, and every time it has bitten me (or my coworkers) in the ass.<p>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?<p>It sometimes reduces coding efforts, but it is the living embodiment of the saying, &quot;If you&#x27;re as smart as you can be when you write it, how will you ever debug it?&quot;<p>It&#x27;s just too much magic spread over too wide an area. I&#x27;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.<p>Again, maybe I&#x27;m just not enlightened enough.
评论 #8028747 未加载
评论 #8027349 未加载
评论 #8027696 未加载
FranOntanayaalmost 11 years ago
I&#x27;ve found myself wanting at times to keep logging outside the fuction, but then I realized I would have to write a lot of extra comments to fill in for the documentation the logging itself provides.<p>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.
yazaddaruvalaalmost 11 years ago
I&#x27;ve always wondered why only Java seems to have this concept.<p>I haven&#x27;t quite dug into a &quot;real&quot; macro system (I don&#x27;t mean the c macro system) but is it that a good macro system is able to replace(&quot;emulate&quot;) AOP?
hexleoalmost 11 years ago
The first time I met AOP is I use Spring framework. AOP is a good thing for logging or authorization check, very powerful.
Dewiealmost 11 years ago
It would be cool to see a comparison between AOP and the monad stacks of Haskell.