From: Junio C Hamano <gitster@pobox.com>
To: Caleb White <cdwhite3@pm.me>
Cc: shejialuo <shejialuo@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH v3 1/3] worktree: refactor infer_backlink() to use *strbuf
Date: Thu, 10 Oct 2024 13:03:30 -0700 [thread overview]
Message-ID: <xmqqcyk7k9nx.fsf@gitster.g> (raw)
In-Reply-To: <J1frhnJqftB1IUvIGDnJiz6uYTDNl_Bc92NLj1gXJtgRxapI3Uy-fyFHYtv5_p8e7yzF0pegawV6NlHQTn0GHcXP8MZ_1X8CNkIvO3_MP9c=@pm.me> (Caleb White's message of "Thu, 10 Oct 2024 17:52:49 +0000")
Caleb White <cdwhite3@pm.me> writes:
>> If so, why not just return "infer_backlink.len"?
>
> I would say because the purpose of the return is a boolean,
> either the call was successful or it wasn't. The developer
> knowledge that you speak of should be a given---if the
> function returned true then there's obviously a path
> in the strbuf.
That does not say what should be left in the strbuf when the request
failed. If it is undefined, then using its .len (or .buf) is not
quite right, without relying on too much implementation details of
the called function.
Usually, this project uses 0 to signal a success, while errors are
signalled by returning a negative value (and if there can be
multiple ways to fail, such a design leaves different negative
values as a possibility).
If the result the caller finds useful is always positive value (or
non-negative value), however, it is perfectly fine and often more
convenient if you used the "positive (or non-negative) value gives
the intended result and signals a success, negative (or
non-positive) value signals an error" convention. The caller can
if (0 < do_the_thing())
; /* success */
just fine, instead of the boolean "0 is success, negative values are
various errors",
if (!do_the_thing())
; /* success */
when it does not care how/why the thing failed.
next prev parent reply other threads:[~2024-10-10 20:03 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 3:12 [PATCH v3 0/3] Link worktrees with relative paths Caleb White via B4 Relay
2024-10-08 3:12 ` [PATCH v3 1/3] worktree: refactor infer_backlink() to use *strbuf Caleb White via B4 Relay
2024-10-10 15:52 ` shejialuo
2024-10-10 16:41 ` Caleb White
2024-10-10 17:26 ` shejialuo
2024-10-10 17:52 ` Caleb White
2024-10-10 20:03 ` Junio C Hamano [this message]
2024-10-10 20:24 ` Caleb White
2024-10-10 19:14 ` Junio C Hamano
2024-10-08 3:12 ` [PATCH v3 2/3] worktree: link worktrees with relative paths Caleb White via B4 Relay
2024-10-08 23:09 ` Junio C Hamano
2024-10-09 18:34 ` Caleb White
2024-10-09 19:10 ` Junio C Hamano
2024-10-09 19:19 ` Caleb White
2024-10-09 23:37 ` Junio C Hamano
2024-10-10 17:30 ` Caleb White
2024-10-11 4:03 ` Caleb White
2024-10-22 4:32 ` Caleb White
2024-10-09 10:11 ` Phillip Wood
2024-10-09 18:49 ` Caleb White
2024-10-08 3:12 ` [PATCH v3 3/3] worktree: add test for path handling in linked worktrees Caleb White via B4 Relay
2024-10-08 4:48 ` [PATCH v3 0/3] Link worktrees with relative paths Caleb White
2024-10-08 19:00 ` Junio C Hamano
2024-10-08 21:55 ` Caleb White
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=xmqqcyk7k9nx.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=cdwhite3@pm.me \
--cc=git@vger.kernel.org \
--cc=shejialuo@gmail.com \
/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.
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).