From: phillip.wood123@gmail.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: Fri, 4 Oct 2024 10:00:49 +0100 [thread overview]
Message-ID: <c37e4dd0-9ad0-4d96-9d0e-ee13d64eb7a0@gmail.com> (raw)
In-Reply-To: <Zv3DehUxEN6SJI1M@tapette.crustytoothpaste.net>
Hi brian
On 02/10/2024 23:04, brian m. carlson wrote:
> On 2024-10-02 at 09:54:52, Phillip Wood wrote:
>> On 30/09/2024 23:03, brian m. carlson 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.
>
> Yes, I agree that this is more verbose than in Rust. If we were using
> Rust (which is a thing I'm working on), then we'd have nicer error
> handling, but for now we don't.
>
> 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 feel like I'm missing something - what is the advantage of returning
an error struct rather than passing it as a parameter that makes the
inconvenience of handling the return value worth while?
>> In conclusion I like the general idea but have concerns about the verbosity
>> of returning an error struct. It would be helpful to see some examples of
>> this being used to see how it works in practice.
>
> If I send a v2, I'll try to wire up some code so folks can see some
> examples.
I think that would be really helpful. A couple of examples in the cover
letter showing how you'd convert some function from our codebase would
give us an idea of what using this api would look like in practice.
Best Wishes
Phillip
next prev parent reply other threads:[~2024-10-04 9:00 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
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 [this message]
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=c37e4dd0-9ad0-4d96-9d0e-ee13d64eb7a0@gmail.com \
--to=phillip.wood123@gmail.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).