News for hackers. Stuff that matters.
Re:Expectations for generics in Go 1.18 by akavel on Thursday October 28, 2021 @06:41AM (#29024426)
AFAIR, Zig has an open issue on how to pass additional context with errors, such as e.g. row & col where a syntax error happened.
Re:Expectations for generics in Go 1.18 by dnautics on Thursday October 28, 2021 @10:54AM (#29026801)
To clarify I thin parent means syntax error I'm the sense of "I'm parsing a (code) file at runtime and there's a syntax error", not a language syntax error.

I mean there's nothing stopping you in zig from creating a rich "error" struct and returning a union of the struct with whatever you would have done otherwise. You only lose the error return trace.

Re:Expectations for generics in Go 1.18 by topspin on Thursday October 28, 2021 @01:09PM (#29028396)
"I mean there's nothing stopping you in zig from creating a rich "error" struct"

Thus Rust's std::result::Result<T, E> where the E in Err(E) is anything that implements the std::result::Error trait.

Rust got this right. It satisfies most use cases with the least possible noise and accommodates the weird ones easily, and does it in a std:: codified manner where no one has to wonder whether or not there is anything stopping them.

Re:Expectations for generics in Go 1.18 by dnautics on Thursday October 28, 2021 @04:04PM (#29031141)
Have you seen what a "rich error struct union" looks like in zig? It's very easy and very legible code. I'd further bet that there are no cases when you're doing this that you want an error return trace. And the downstream handling code is very easy.

If there is a problem with how it's done in zig, it's a community one: maybe the pattern needs a megaphone beside it, like examples in the main docs or tuts in the various zig tut sites that have cropped up

Re:Expectations for generics in Go 1.18 by topspin on Friday October 29, 2021 @12:50PM (#29040732)
"Have you seen what a "rich error struct union" looks like in zig?"

No, and I'm not arguing that zig hasn't done well. I do argue that Go has not; you're only non-weird choice is to fetter code with miles of "if err ==/!=" gymnastics.

Traces are frequently very useful; precise traces have saved me a lot of pain in life. Lack of traces precludes nothing for me, but I have enjoyed the benefit of them enough times to acknowledge their great value.

Re:Expectations for generics in Go 1.18 by dnautics on Friday October 29, 2021 @06:54PM (#29044425)
Traces are fantastic for unexpected errors. You don't need them, for example, when validating user input, which is the type of system where you want richer errors.
Re:Expectations for generics in Go 1.18 by steveklabnik on Thursday October 28, 2021 @01:31PM (#29028657)
(E is not required to implement that trait, it just often does)