TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Aspect-Oriented Programming

90 点作者 alraj将近 2 年前

27 条评论

tjansen将近 2 年前
I am happy that AOP never really caught on. The idea of modifying the behaviour of a class in a completely different place of the source tree has always horrified me. Makes it pretty much impossible to understand code by just looking at a single file.<p>Admittedly, IDEs were pretty rudimentary when AOP was first introduced, and today&#x27;s IDEs can display aspects right where they are applied. But I still think that annotations&#x2F;decorators are a far better solution for the problem that AOP tried to solve.
评论 #36323195 未加载
评论 #36322899 未加载
评论 #36327752 未加载
评论 #36323567 未加载
评论 #36327547 未加载
评论 #36323332 未加载
评论 #36323575 未加载
评论 #36326057 未加载
评论 #36339837 未加载
评论 #36326613 未加载
gorjusborg将近 2 年前
AOP creates &#x27;hidden coupling&#x27;, something I found extremely common while working in java.<p>The logic seems to be that loose coupling is better than tight coupling, and what&#x27;s looser than zero coupling? It&#x27;s perfect!<p>The trouble is that zero coupling is not really possible in a working system. Instead what you&#x27;ve done is introduce &#x27;hidden coupling&#x27;, where one can&#x27;t see the connections between components in the system from the code.<p>Hidden coupling makes understanding and maintaining a software system much harder than it would be otherwise.
评论 #36324338 未加载
评论 #36326531 未加载
aspyct将近 2 年前
Oh, I made an AOP library for python when I started uni back in 2008. That&#x27;s actually where my nickname comes from: aspyct (a concatenation of aspect, python and aspyc).<p>Sadly I lost the contents of the old wiki. I did pour a lot of energy into that :) But I still have a page on my old blog: <a href="https:&#x2F;&#x2F;www.aspyct.org&#x2F;aspyct&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.aspyct.org&#x2F;aspyct&#x2F;</a> (funny URL though \o&#x2F;)<p>It&#x27;s never been a huge hit, but from time to time I would get emails from students who were investigating it for a university project. That was fun :)<p>Is was adding some interesting features (notably pointcuts), but ultimately it didn&#x27;t bring enough added value compared to a simple decorator in python, and I ceased development.<p>It&#x27;s still available on SourceForge, for those interested: <a href="https:&#x2F;&#x2F;sourceforge.net&#x2F;projects&#x2F;aspyct&#x2F;files&#x2F;aspyct&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;sourceforge.net&#x2F;projects&#x2F;aspyct&#x2F;files&#x2F;aspyct&#x2F;</a><p>EDIT: wow that was 15 years ago. I&#x27;m not getting younger :p
mbork_pl将近 2 年前
Emacs Lisp has AOP built in [0], and in this context it is <i>extremely</i> useful. The common use case is <i>advising</i> functions of a third-party library without modifying the library itself (which wouldn&#x27;t survive e.g. an upgrade). This is a bit atypical, though, in that the end user is a programmer here. A blog post I wrote last year [1] is one example of advising functions sitting pretty deep in the chain of function calls to achieve something useful.<p>That said, even the manual says [2]:<p>&gt; advice-add can be useful for altering the behavior of existing calls to an existing function without having to redefine the whole function. However, it can be a source of bugs, since existing callers to the function may assume the old behavior, and work incorrectly when the behavior is changed by advice. Advice can also cause confusion in debugging, if the person doing the debugging does not notice or remember that the function has been modified by advice.<p>&gt; For these reasons, advice should be reserved for the cases where you cannot modify a function’s behavior in any other way.<p>[0] <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Advising-Functions.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Ad...</a> [1] <a href="https:&#x2F;&#x2F;mbork.pl&#x2F;2022-09-17_Safe_killing_with_Emacs" rel="nofollow noreferrer">https:&#x2F;&#x2F;mbork.pl&#x2F;2022-09-17_Safe_killing_with_Emacs</a> [2] <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Advising-Named-Functions.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Ad...</a>
评论 #36343844 未加载
lastangryman将近 2 年前
Ah this takes me back to my first job. Medical start up, working on a very long term project that the company was completely unequipped to deliver. I was young and keen so didn&#x27;t appreciate the context, I just did stuff.<p>For some reason, we hired an &quot;architect&quot; from a large Bank that used Java. He used to make proclamations like &quot;we should write tests&quot;, but never actually got into more detail than that. One of his preachings was about aspect oriented programming and how it was going to be future. He did a talk on it, and I remember someone asking &quot;what else does it apply to apart from logging and Auth?&quot;...no answer.<p>Not long after, I left. 2 years there, probably over 15 engineers, I don&#x27;t think we built anything close to a functioning software product.
评论 #36322295 未加载
评论 #36322119 未加载
评论 #36322621 未加载
SCdF将近 2 年前
I did an AOP project back in ~2007, where we used crosscutting to separate the frontend from the backend, due to the belief that in the future we would swap out the thick client frontend for a web client.<p>It was kind of a nightmare (to put it kindly). This was an insurance app where updates in the frontend would automagically be pushed into the backend algorithm, which would automagically push changes to the frontend, which would automagically push changes to the backend...<p>The client also didn&#x27;t pay for regression tests (2007 was a long time ago!) so basically every week it infinite loop locked in some new and undebuggable way.
culturedsystems将近 2 年前
The paper linked to in the Criticism section of the article [1] is well with reading, IMO. It points out that AOP only works when there is &quot;obliviousness of application&quot;, i.e the code to which the aspect is applied doesn&#x27;t need to know about the aspect, and argues that this kind of obliviousness is pretty rare.<p>1: <a href="http:&#x2F;&#x2F;onward-conferences.org&#x2F;2009&#x2F;files&#x2F;steimannessay.pdf" rel="nofollow noreferrer">http:&#x2F;&#x2F;onward-conferences.org&#x2F;2009&#x2F;files&#x2F;steimannessay.pdf</a>
hejcloud将近 2 年前
I think AOP is a fair tool.. for maybe 1% of of your day to day problems.<p>I&#x27;d say it&#x27;s okay to use in combination with OOP when you (and your team) manage to strictly keep the Domain&#x2F;Business stuff in OOP world and the infrastructural stuff (logging) in AOP. Whenever you start mixing any of these together or have overlapping concerns, then things will quickly get very messy. While logging is fine with AOP e.g. with Access control things easily get mixed up over time.<p>When I look back the last 1-2 decades, the pattern that I see is that one principle always won: Simplicity.<p>I&#x27;d like to end up with a little war story:<p>In 2017 I happened to work at a startup (~60 engineers) that started with a gazillion of Microservices in dozens of different languages and ecosystems. Then there was this Clojure guy that didn&#x27;t even do that much of missionary work. When people started reading each others codebases they realized the simplicity of Clojure and later started porting&#x2F;rewriting their things to it. At the same time, everything Scala was frowned upon; I vividly remember trying to understand the request a supposedly simple CRUD service was making to another service and I couldn&#x27;t understand the program flow for like 2h. Needless to say that probably like 80% of the services ended up being rewritten in Clojure and the Clojure guy got called the Johnny Appleseed of the company.
invalidname将近 2 年前
A more practical explanation of stuff you can do with AOP that would be challenging otherwise: <a href="https:&#x2F;&#x2F;debugagent.com&#x2F;spring-boot-debugging-with-aspect-oriented-programming-aop" rel="nofollow noreferrer">https:&#x2F;&#x2F;debugagent.com&#x2F;spring-boot-debugging-with-aspect-ori...</a>
评论 #36326399 未加载
larsrc将近 2 年前
I worked on AspectJ during a summer internship at Xerox PARC i n 2000. Very interesting, but did not convince me that AOP was a good thing. They had a few good examples (logging was the big one), but added so many advanced features to support other use cases that the code ended up being very hard to understand. Same problem I have with Guice.
yodon将近 2 年前
It&#x27;s odd to see posts saying &quot;Aspect-Oriented Programming never caught on.&quot;<p>All game developers know Aspect-Oriented Programming, just not by that name, because it&#x27;s at the core of one of the most successful platforms in the industry.<p>Unity3d is a $14B company built in large part on Aspect-Oriented Programming and Aspect-Oriented Design.<p>Every time you implement a Unity Behavior in C#, you&#x27;re doing Aspect-Oriented Programming in a text editor. Every time you drag a Behavior onto a Game Object in the Unity Editor, you&#x27;re doing Aspect-Oriented Programming in a graphical programming environment.
评论 #36330127 未加载
Omroth将近 2 年前
I was already dubious of the concept, but the account example in the page makes me even more so.<p>&quot;Transactions, security, and logging all exemplify cross-cutting concerns.&quot;<p>Logging, maybe. Transactions and security? Hard disagree.<p>And then in the example it checks for enough funds to make the withdrawal, and then makes the withdrawal, not as an atomic ation. I don&#x27;t think that&#x27;s just nit-picking on a simple example - how AOP interacts with atomic actions is fundamental to the use-case.
kazinator将近 2 年前
The joke language INTERCAL incorporated AOP. In INTERCAL, the GOTO statement is replaceed by COMEFROM.<p>If you write a COME FROM 20 anywhere in the program, then when line 20 executes, control will invisibly pass to your COMEFROM statement.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;INTERCAL" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;INTERCAL</a><p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;COMEFROM" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;COMEFROM</a>
zoogeny将近 2 年前
I recall learning about aspect-oriented programming (AOP) waaaaay back in the day. This was before inversion of control patterns and dependency injection frameworks mostly solved that problem space in the OOP languages I was dealing with. Even before that, most people just used singletons or some kind of service locater pattern.<p>Now that I spend a lot of time using Typescript, I find I rarely have the same issues that required those solutions. I believe that is due to the module system but I&#x27;m not entirely sure. I&#x27;m trying to think of the classic AOP problems, like structured log providers. Maybe it is the standardization of logging interfaces and the fact that I can trivially write adapters that makes this a non-issue for me these days?<p>I suppose, things like context managers [1] in React solve a similar problem space. That is probably the closest modern equivalent annoyance I can think of to the kind of problem that AOP was designed to solve.<p>To be honest, the tools I&#x27;ve had available were always able to solve the problem well enough. Every AOP solution I have seen is an order of magnitude more complicated than the problem it was trying to solve.<p>1. <a href="https:&#x2F;&#x2F;react.dev&#x2F;reference&#x2F;react&#x2F;useContext" rel="nofollow noreferrer">https:&#x2F;&#x2F;react.dev&#x2F;reference&#x2F;react&#x2F;useContext</a>
shanghaikid将近 2 年前
Dojo&#x27;s aspect feature is one of my favorite feature in the framework.<p><a href="https:&#x2F;&#x2F;dojotoolkit.org&#x2F;reference-guide&#x2F;1.9&#x2F;dojo&#x2F;aspect.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;dojotoolkit.org&#x2F;reference-guide&#x2F;1.9&#x2F;dojo&#x2F;aspect.html</a><p>Now dojo is gone. But sometimes I still will port this feature into react&#x2F;vue project.
rektide将近 2 年前
Javascript annotations are finally landing &amp; they are very much enabling aop like concerns.<p>Alas none of thr original greatness of javascript has been allowed. The new language features are all 100% special snowflake things, miles apart from the everything-is-an-object world we had. So these annotations&#x2F;transforms are load-time only. They make a bunch of changes to your classes or whatever as the class loads then they are erased, invisible, totally unable to be seen unless explicitly coded.<p>Dripping disdain for this weak ass shitty path JS has started following. We keep making invisible unreflective shit &amp; it&#x27;s all super shit. Private fields can&#x27;t be reflected on at all. ESM took over half a decade to get any kind of module metadata like import.meta and there is absolutely positively none of the module registry notions we were talking up as ESM was being crafted.<p>Everything is a huge downgrade for a runtime where you can look around &amp; see what you have. To me, the neat spirit of AOP is when you not just attach some static annotations &amp; compile it away, but when the runtime can keep growing new ways to be self aware. When you can keep compounding &amp; meta-mutating. But the language design keeps shoving us down narrower more limited paths where the runtime actively tries to blind itself. There&#x27;s such a huge massive narrative here on language design, &amp; it should be in textbooks &amp; screamed out loud, but it&#x27;s invisible &amp; unseen &amp; the forces of conservative secure encapsulation &amp; hiding are the only ones with any power or say &amp; everyone else is losing. We have AOP about to happen but it&#x27;s sad AOP, ignorant AOP, blind AOP.<p>Dynamic runtime AOP is just one of many capabilities - like DI&#x2F;dependency Injection - where really what we are doing is creating a powerful metaplatform for resources, for object instances (and factories). Having management over objects is intensely interesting &amp; empowering. Declarative code is just a cheap way to explicitly wire up resources&#x2F;instances, with no management layer. I loved &amp; hope we get back to more interesting &amp; ambitious times when object repositories become powerful interesting object generating &amp; manipulating entities.
kgeist将近 2 年前
I&#x27;ve seen the classic examples of AOP being used to log or authorize, but you can easily do that without &quot;cluttering your code&quot; by using the decorator pattern? Decorators are also nestable (when you want to both log and authorize).
评论 #36322041 未加载
评论 #36321965 未加载
评论 #36325894 未加载
seanparsons将近 2 年前
I remember writing a state machine system for a project to replace Windows Workflow Foundation (shudders) using Aspect.Net (IIRC) many years ago and it working but being a faff.<p>But then I think to something like the bracket function from Haskell: <a href="https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;base-4.18.0.0&#x2F;docs&#x2F;Control-Exception.html#v:bracket" rel="nofollow noreferrer">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;base-4.18.0.0&#x2F;docs&#x2F;Contr...</a> That&#x27;s 2 orders of magnitude simpler and doesn&#x27;t need arbitrary function definitions so a pointcut can be defined against a block of code.
gloryjulio将近 2 年前
The reason react hooks get so much hate it&#x27;s because that it&#x27;s basically Aspect-Oriented Programming. If ur project scope is small and u don&#x27;t get why you need it in the first place, then it looks weird and unintuitive. But when u work on bigger projects and u have some many shared HOCs which are stacked, they become callback hells to manage and debug.<p>But hooks solve this cross cutting problem. It&#x27;s like going from promise callback hells to async await.
liampulles将近 2 年前
In my experience, it&#x27;s best to keep AOP usage limited to very well defined areas. Logging is fine, making your own AOP stuff is often a recipe for overly clever code.
barbariangrunge将近 2 年前
Question: how do you think the binding of isaac lets you mix and match so many abilities? The number of item&#x2F;effect synergies is really striking in that game. Is it a series of decorators, or something AOP like?<p>My personal theory is it&#x27;s something decorator like that involves modifying something like a struct which gets converted into game effects after all the modifiers run<p>This article just made me wonder about this again
评论 #36322648 未加载
评论 #36322316 未加载
评论 #36322668 未加载
评论 #36322798 未加载
brokenkebaby将近 2 年前
Since I learned what is it it&#x27;s been my strong feeling that AOP is a very big (and somewhat misleading) name for such a small thing
Simon_O_Rourke将近 2 年前
I dabbled a bit using AOP in college, mostly trying to get software to do new things via dynamic updates.<p>It was the most awful paradigm to use, had to develop a test harness just to figure out the configuration and control flow for experiments.<p>For it&#x27;s very niche use cases I&#x27;m sure it&#x27;s interesting, for anything else it&#x27;s just too difficult.
thom将近 2 年前
There is no level of abstraction at which you can write code that won&#x27;t simultaneously be too obstruse for some, and an impossible maintenance burden to others. There is no programming paradigm, language, framework or tool that is going to fix this.<p>Fun to argue though.
评论 #36333071 未加载
w10-1将近 2 年前
As others have noted, AspectJ was&#x2F;is used in Spring, so it had a long, useful life. IBM also used it to layer in closed-source enterprise features on their open-source web server, particularly for error-handling.<p>AOP&#x2F;AspectJ won the space, beating out the more analytical program-slicing approaches which were incomprehensible to most. Pointcuts were more understandable than slices.<p>It&#x27;s best not to reduce AOP to interception or weaving. While &quot;crosscutting concerns&quot; was the animating motivation, Kiczales regretted giving any toe-hold for mechanistic ideas of AOP and removed the notion of &quot;crosscut&quot; or &quot;weaving&quot; from the language and messaging (even though load-time binary weaving was the driving feature for adoption). There were (toy) implementations in C++ et al.<p>The core idea is that a program has well-understood places and times - where&#x27;s and when&#x27;s - that a language should capture as one when they have integrity while preserving language semantics. So the join point model targets programmer-understandable things (like method call or exception handling), not just anything (like loops), and preserves type-safety and access control. Similarly, type-extensions (&quot;inter-type declarations&quot;) were binary-compatible with the original code. Unlike extensions in Swift or Objective-C, these extensions could add state to an object, which could be published or just used privately by the aspect (traits or mixin&#x27;s anyone?). Aspect instances could be created staticly, one-per-instance of an object, and even once per control-flow&#x2F;thread, esp. to tunnel information from high in the call stack down below (i.e., through library call-backs, if in thread).<p>Tooling support was always a strong concern. It started with its own debugger and IDE, but was really a perfect match for Eclipse (and Java&#x27;s then-new support for debug context for any language in bytecode). The Eclipse compiler beat javac by focusing on incremental builds, making Eclipse the best place to code. The compiler has always had to be forked and extended to support AspectJ, which is something of a black art. But it did mean you could browse any pointcuts in a code base, leaving some to use it for its program-slicing abilities :)<p>Obliviousness (like private static) is the safe default, but AspectJ also supported aspect-aware code with public extensions. So there were a range of aspects, from benign observers, through essential but still oblivious security&#x2F;audits, to public aspects forming feature layers in a product-family scheme.<p>Today, Swift has many AOP-like features, and Python context managers transformed the language (so yeah, loops are sensible join points). But AspectJ was tied to Java, and all the enterprise programming-container models were careful to keep programs dependent on the containers (read: oracle databases with in-memory VM&#x27;s and IBM JVMs). There&#x27;s no after advice for handler join points because Java bytecode doesn&#x27;t have determinate points for that. Generics and method and field handles strained the language when there has been just a few heroic maintainers. There was lots of discussion for extending the notion of control flow across threads and machines (like tracing now), but no real support in bytecode (and not enough consistency in thread models or package loading conventions to make any implementation broadly available).<p>And there were hard problems: can you weave an already-woven class? After much analysis and discussion, the simple answer won: The original class was preserved in the woven class as an annotation (bloating the disk size, but not the size as loaded), and that was used instead of trying to unweave the woven bytecode.<p>AspectJ survived for a long time both through careful semantics and by making a lot of pragmatic engineering decisions, in both cases stretching to make it usable for ordinary programmers. But it was always a derivative of Java, and was embraced&#x2F;extended (and monetized and contained) by Spring. (Adrian Colyer was handed the project as it moved to Eclipse, and was the CTO of Spring.)<p><a href="https:&#x2F;&#x2F;www.eclipse.org&#x2F;aspectj&#x2F;doc&#x2F;next&#x2F;progguide&#x2F;index.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.eclipse.org&#x2F;aspectj&#x2F;doc&#x2F;next&#x2F;progguide&#x2F;index.htm...</a>
voz_将近 2 年前
Great way to get mired down in bullshit.
jonnycomputer将近 2 年前
The article says implemented in Python, but doesn&#x27;t say how or where. Anyone know? Decorators?