From: Eric Sunshine <sunshine@sunshineco.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>,
phillip.wood@dunelm.org.uk, git@vger.kernel.org,
Emily Shaffer <nasamuffin@google.com>,
Junio C Hamano <gitster@pobox.com>,
Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Subject: Re: [RFC PATCH 1/1] Add a type for errors
Date: Wed, 2 Oct 2024 18:16:00 -0400 [thread overview]
Message-ID: <CAPig+cRkA58wr_Pn-uhVM0zFA7B0hnArXDeumrjnWrgBbG64Yw@mail.gmail.com> (raw)
In-Reply-To: <Zv3DehUxEN6SJI1M@tapette.crustytoothpaste.net>
On Wed, Oct 2, 2024 at 6:04 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> On 2024-10-02 at 09:54:52, Phillip Wood wrote:
> > Part of the reason it works well in rust is that it supports discriminated
> > unions with pattern matching and has the "?" macro for early returns. In C
> > the code ends up being quite verbose compared to taking a pointer to error
> > struct as a function parameter and returning a boolean success/fail flag.
> >
> > struct git_error e;
> > struct object_id oid;
> >
> > e = repo_get_oid(r, "HEAD", &oid);
> > if (!GIT_ERROR_SUCCESS(e))
> > return e;
> >
> > With a boolean return we can have
> >
> > struct object_id oid;
> >
> > if (repo_get_oid(r, "HEAD", &oid, e))
> > return -1;
> >
> > where "e" is a "struct git_error*" passed into the function.
>
> However, Go still uses this kind of error handling, and many people use
> it every day with this limitation, so I don't think it's too awful for
> what we're getting. I won't say that Go is my favourite language and I
> do prefer the less verbose error handling in Rust, but the fact that
> this design is widely used means that it's at least a defensible
> decision.
I'm not sure I understand your response to Phillip's observation.
Idiomatic error handling in Go:
if oid, err := repo_get_oid(r, "HEAD"); err != nil {
return err;
}
seems much closer to Phillip's more succinct example than to the more
verbose example using GIT_ERROR_SUCCESS().
next prev parent reply other threads:[~2024-10-02 22:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 22:03 [RFC PATCH 0/1] Typed errors brian m. carlson
2024-09-30 22:03 ` [RFC PATCH 1/1] Add a type for errors brian m. carlson
2024-09-30 22:44 ` Junio C Hamano
2024-09-30 23:35 ` brian m. carlson
2024-10-21 12:46 ` Patrick Steinhardt
2024-10-01 15:29 ` Oswald Buddenhagen
2024-10-02 14:01 ` Phillip Wood
2024-10-01 20:31 ` Emily Shaffer
2024-10-02 21:51 ` brian m. carlson
2024-10-02 9:54 ` Phillip Wood
2024-10-02 22:04 ` brian m. carlson
2024-10-02 22:16 ` Eric Sunshine [this message]
2024-10-02 22:24 ` brian m. carlson
2024-10-03 5:14 ` Eric Sunshine
2024-10-03 16:05 ` Junio C Hamano
2024-10-03 22:27 ` Eric Sunshine
2024-10-04 0:15 ` brian m. carlson
2024-10-04 9:00 ` phillip.wood123
2024-10-04 12:13 ` Richard Kerry
2024-10-03 16:17 ` Emily Shaffer
2024-10-04 9:00 ` phillip.wood123
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=CAPig+cRkA58wr_Pn-uhVM0zFA7B0hnArXDeumrjnWrgBbG64Yw@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=nasamuffin@google.com \
--cc=oswald.buddenhagen@gmx.de \
--cc=phillip.wood@dunelm.org.uk \
--cc=sandals@crustytoothpaste.net \
/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).