all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Use of advice   [was: Is it valid to call isearch-filter-predicate outside isearch?]
@ 2023-06-03 15:22 Drew Adams
  2023-06-06 23:36 ` Michael Heerdegen
  0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2023-06-03 15:22 UTC (permalink / raw)
  To: Ihor Radchenko, Michael Heerdegen; +Cc: emacs-devel@gnu.org

> >> 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.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-06-08  1:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-03 15:22 Use of advice [was: Is it valid to call isearch-filter-predicate outside isearch?] Drew Adams
2023-06-06 23:36 ` Michael Heerdegen
2023-06-07  2:01   ` [External] : " Drew Adams
2023-06-07  2:53     ` Michael Heerdegen
2023-06-07 14:44       ` Drew Adams
2023-06-08  1:30         ` Michael Heerdegen
2023-06-07 11:53     ` Ihor Radchenko
2023-06-07 11:49   ` Ihor Radchenko
2023-06-07 14:47     ` [External] : " Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.