Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Just thinking out loud, given Zig's errors primarily allow the compiler to enforce that errors are handled, and exhaustively, beyond that why can't error payloads just be passed as an input argument pointer to the function call?

Yeah, that's definitely a reasonable way to do it, and actually Andrew gives an example of this:

https://github.com/ziglang/zig/issues/2647#issuecomment-5898...

(Andrew's example is slightly different in that rather than an explicit argument, it's an optional field in one of the arguments.)

So it's definitely not like crazy bad or anything, but also definitely less ergonomic than if you could directly return a payload with the error, and this is enough friction that it feels like you'll end up not having error information when you want it (both as an API consumer and eventually as an end-user looking at an error message).

But, I'm still very new to Zig, so perhaps my instincts on that are wrong. :-)



> But, I'm still very new to Zig, so perhaps my instincts on that are wrong. :-)

Maybe you're right too! Just speaking for myself here, but as a programmer and "man with a hammer", I sometimes like to think that instincts might just be our mental machine learning model, where it can be really well trained and give the right black box answer, albeit not with the explanatory backstory or rationale, but worth trusting nevertheless.

I'm also new to Zig, and there are ways that a pointer input arg as error payload could go wrong. I'm following the proposal issue, and it will be interesting to see which way it goes.


I think you're spot on with your description of instincts. Which of course means sometimes they can lead us wrong, especially if we're applying them to domains very different from those they were trained on.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: