[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Use of advice [was: Is it valid to call isearch-filter-predicate outsi
From: |
Drew Adams |
Subject: |
Use of advice [was: Is it valid to call isearch-filter-predicate outside isearch?] |
Date: |
Sat, 3 Jun 2023 15:22:08 +0000 |
> >> 2. It feels against the interface. If advising this predicate is
> >> expected, why not convert it into an abnormal hook?
> >
> > It's more flexible and expressive, as Drew already mentioned. For
> > example, how the members of a hook are logically combined (`and'ed,
> > `or'ed) is fixed in a hook, but not when using advising.
>
> Interesting.
> From Elisp Tips in the manual, I always felt that using advices is
> always frowned upon. And you are suggesting that they are the better way
> to go in these situations.
> I am wondering if this thing with modifying predicates should be
> documented somewhere and recommended approach.
This is a good point/question.
FWIW, IMO (so far) - and obviously I don't speak
for Emacs and I'm no expert on this:
1. I think the guideline is (has been) for Emacs
code (i.e., what GNU Emacs delivers) to avoid
use of advice in favor of hooks etc.
It may also be a useful guideline for users,
but I think it's more for Emacs developers.
The reasons given for the avoidance include
that the use of advice is opaque/complicated
- it can make things harder for users (or for
other code) to see and analyze what's going
on (e.g. in a debugger).
This is an important consideration.
2. There's a difference between the old advice
and the new one (nadvice). Dunno how relevant
it might be, here. The capabilities,
opaqueness, and fragility of the two aren't
the same, I think.
The general guideline to avoid use of advice
was established when the old advice was used.
Maybe it needs some nuance/seasoning now (?).
3. #1 doesn't take away from the fact that advice
(particularly nadvice) also offers additional
flexibility/power. A hook or a function-valued
variable doesn't offer the same things. IOW,
there are upsides as well as downsides to using
advice.
But I think it's still generally true that IF
you can do XYZ just as well without using advice,
THEN do so. What's good is to understand the
tradeoffs.
4. Yes, it might be good to (somehow) document the
use of advice more/better, including tradeoffs
involved.
This won't be easy to do well, I expect. Someone
who knows nadvice well, like Stefan or Michael H,
might need to get involved, to come up with
accurate & useful guidance for us mere users. ;-)
If done poorly the result might be worse than the
current relative lack of such guidance. Or not.
We won't know till someone tries.
- Use of advice [was: Is it valid to call isearch-filter-predicate outside isearch?],
Drew Adams <=