On Wed, Oct 2, 2024 at 6:04 PM brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> 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().