zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Marlon Richert <marlon.richert@gmail.com>
Cc: Daniel Shahaf <d.s@daniel.shahaf.name>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Does add-zle-hook-widget violate the contract of ZLE hook widgets?
Date: Fri, 25 Jun 2021 10:34:08 -0700	[thread overview]
Message-ID: <CAH+w=7YHPjpC9QFuteEPpeitXcZmfe9nEtWVqUkQOy5_4VHWDA@mail.gmail.com> (raw)
In-Reply-To: <CAHLkEDtte64OOGYo=mr_FgEbaW1Dn8U+wjE2WE0s-v5tnq1WDw@mail.gmail.com>

On Thu, Jun 24, 2021 at 2:49 PM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> That makes sense, but then, it should also be documented what that
> actually means. If your function returns zero/non-zero, what is
> expected to happen? Does this always happen? Or are there different
> classes of functions with different results for zero/non-zero?

The convention is that returning zero means success (the canonical
example being the "true" command) and nonzero means some kind of
failure ("false").  The actual numeric value of the non-zero return
might mean something.  Theoretically every command (function, builtin,
script, whatever) that "succeeds" should be returning zero; the fact
that this is sometimes ignored (and that for example the return/exit
status of the last command executed within the function body is
retained as $? instead) is programmer laziness.

> I can already think of two examples that contradict each other:
> * In hook functions, callee returning NON-zero causes the caller to
> refrain from calling more functions.
> * In completion functions, callee returning ZERO causes the caller to
> refrain from calling more functions.

These are not really contradictory; you're ignoring important context.
In both cases zero means success and nonzero means failure.  The
context determines what that signifies.

For completion functions, success means that completions have been
generated and further work is not necessary, failure means it's
reasonable to try a different approach.

For hook functions, success means that it's OK to proceed, and failure
means that something bad happened and further work is potentially
dangerous.

You can't just look at the return codes in isolation and say "these
are reversed" without considering what success or failure means in
context.

In either case we could actually extend the model to use different
nonzero values of $? to distinguish "try something else" and "danger,
abort" conditions; it just happens that for hooks, currently anything
nonzero is considered "danger, abort" and for completion it is always
"try something else".


  parent reply	other threads:[~2021-06-25 17:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 20:30 Marlon Richert
2021-06-23 21:57 ` Daniel Shahaf
2021-06-23 23:33   ` Lawrence Velázquez
2021-06-24  0:09     ` Daniel Shahaf
2021-06-24 10:34   ` Marlon Richert
2021-06-24 10:45     ` Roman Perepelitsa
2021-06-24 18:54       ` Daniel Shahaf
2021-06-24 19:51         ` Roman Perepelitsa
2021-06-24 18:30     ` Daniel Shahaf
2021-06-24 21:48       ` Marlon Richert
2021-06-24 22:29         ` Lawrence Velázquez
2021-06-26 10:12           ` Marlon Richert
2021-06-26 14:51             ` Bart Schaefer
2021-06-24 23:52         ` Daniel Shahaf
2021-06-26 10:49           ` Marlon Richert
2021-06-25 17:34         ` Bart Schaefer [this message]
2021-06-27  8:19 Marlon Richert
2021-06-29  2:06 ` Bart Schaefer
2021-06-29 14:50   ` Marlon Richert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YHPjpC9QFuteEPpeitXcZmfe9nEtWVqUkQOy5_4VHWDA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=marlon.richert@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).