Hacker News new | ask | show | jobs
by nextaccountic 315 days ago
> The advantage of this is that everything is explicit, and it is up to the caller to arrange memory usage for error data

Likewise, this has the disadvantage that the caller must allocate space for the error payload, even if the error is very unlikely

1 comments

Well, it is an optional parameter (my typo made that unclear), so the caller may omit it if desired. The reason for this particular tradeoff, is in favour of correctness rather than convenience, eg. if the failure is in an OOM condition, it can still be reported.
Ok this sounds nice. You would just need some syntax sugar to make this ergonomic (both in the side of function calling, and also in the side of the erroring function) but the fundamentals seem solid

I think there's space for a post-Rust, post-Zig language to combine the approaches of both and make it possible to do away with automatic heap allocation (when needed - not every piece of code wants to bother with this), but also don't make code overly verbose when doing so.