3 ms·
Emacs Lisp has AOP built in [0], and in this context it is extremely useful. The common use case is advising functions of a third-party library without modifyi
by mbork_pl 3y ago
Emacs Lisp has AOP built in [0], and in this context it is extremely useful. The common use case is advising functions of a third-party library without modifying the library itself (which wouldn'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.
That said, even the manual says [2]:
> 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.
> For these reasons, advice should be reserved for the cases where you cannot modify a function’s behavior in any other way.
[0] https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ad...
[1] https://mbork.pl/2022-09-17_Safe_killing_with_Emacs https://mbork.pl/2022-09-17_Safe_killing_with_Emacs
[2] https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Named-Functions.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ad...
- kqr 3y agoI've always put advice (and Perl's Hook::LexWrap and other implementations) in a different bucket to aspect-oriented programming, with the idea that AOP is used to build an application and advice is used to monkey-patch around a bug that isn't yet fixed upstream. But you're right, they're similar to some degree.