Re:Write Libraries, Not Frameworks
by fulafel on Saturday May 09, 2020 @02:47AM
(#23122803)
For those of us hazy on the AOP concept... Is it an artifact stemming from restrictions of static languages, or would it be a valid concept with dynamic languages too?
[ Parent
| on HN ]
In the dynamic languages world this is done with monkey patching.
If you invent a declarative way to monkey patch your code, you've got AOP as done in Spring.
I believe emacs lisp's advice system is an AOP system in a highly dynamic language, and doesn't make much use of monkey-patching.
Advice/AOP is a pattern that can fit (if you want it) in dynamic language as well.
What about this Clojure library?
Don't forget AOP can work on top of compiled classes, not sure I'd there is an equivalent in python or ruby.
I don’t thin AOP is specific to static languages. From my understanding, the “aspect” part implies the ability to “hook into” and extend an application at specific “cut points”, which are typically pre/post function/method calls. This is done in Java by modifying byte code to insert proxies. I imagine something similar could be developed with other languages. It might just be easier to do in Java because the type signatures are static.
Re:Write Libraries, Not Frameworks
by louiskottmann on Saturday May 09, 2020 @03:30AM
(#23122939)
It is very close to python's @ syntax on top of methods definitions.
Like:
@get('/posts')
mymethod
...?
no, it's not.
look at https://python-aspectlib.readthedocs.io/en/latest/ for an example of using aspect with python
Python decorators are a (limited) form of AOP: they let you transform functions in-place to implement cross-cutting concerns. Aspectlib allows you to do a more intrusive form of AOP.
Re:Write Libraries, Not Frameworks
by louiskottmann on Saturday May 09, 2020 @06:55AM
(#23123681)
Decorators and AOP are very similar concepts in my opinion then, if you prefer.