3 ms·
The advice system is really nice. Is there anything like that in other languages?
by taeric 5y ago
The advice system is really nice. Is there anything like that in other languages?
- kqr 5y agoSomething similar is sometimes discussed under the term "aspect oriented programming". That might help with your Google adventures. (I know there was one black magic implementation of it for C# on Windows at some point and also similar black magic for Java, but that's as far as I've ever explored it other than in Emacs Lisp. (Black magic in this case refers to splicing in the advice in the compiled bytecode of the program.)) Edit: apparently there's some basic implementation for Perl, too, and it's documentation looks like a neat intro to the idea: https://metacpan.org/pod/Aspect https://metacpan.org/pod/Aspect
- taeric 5y agoHmm. Aspect oriented feels different. I have to put the advice at the spot of what I'm advising there. Still, I can see the similarity. Monkey patching comes somewhat close. But lacks the communication of intent that is so clear with advice.
- kqr 5y ago> I have to put the advice at the spot of what I'm advising there. I'm not sure what you mean by this. The idea with aspect-oriented programming is that you can create a bundle of functionality that extends existing functionality but exists as its own separate bundle. In other words, you specifically do not have to put the advice at the same place as the adviced. That would just be regular procedural/functional/objevt-oriented programming, wouldn't it?
- taeric 5y agoIn java, at least, you have to put the annotation in the source where you are going to put the advice. Right? Compared to elisp, where I can put advice around a function that is defined somewhere else, possibly out of my control.
- kqr 5y agoNo. The advice in AspectJ is fully self-contained. You specify -- completely separately in its own place -- what the advice is, and what it is advising. You can advice things that are out of your control. This is indeed the idea of aspect-oriented programming. I'm not sure where you got a different idea. Could you point me that way?
- taeric 5y agoIn the use of aspectj that I have ever seen, it was always an annotation based thing. I could annotate a method as getting logged to get a trace level log. Yes, the logic of doing the trace was somewhere else, but I couldn't place a trace on any invocation of a named method. Say I wanted to log all calls to (make-hash-table), in elisp, that is an easy advice call. In java, I didn't think that was really doable. That said, thinking on some of the tricks I'm ok with in tests, I guess it has to be possible. Not sure what the code looks like. It is amusing, as even the annotation based stuff I've seen is near universally disliked by engineers with experience from it. Seems a very common foot gun, in practice.