News for hackers. Stuff that matters.
Re:Why is Zig so Cool? by qouteall on Saturday November 08, 2025 @12:39AM (#45854452)
If the error rarely happens then passing error data shouldn't affect performance in visible way. If the error occurs in common path then it's designed wrongly.

I agree that in special states like OOM passing error data with allocation is not ok.

Re:Why is Zig so Cool? by 59nadir on Saturday November 08, 2025 @05:29AM (#45855691)
Error data being returned instead of just error codes doesn't require allocation at all, and never would, unless the specific unions that you're returning require as much. Zig already has tagged unions with a tag field and associated payload, that is exactly what you would return. The overhead isn't remarkably worse than the cost of modifying the value someone passed in to "Fill this in in case of errors" (which is what you have to do now in Zig).
Re:Why is Zig so Cool? by qouteall on Saturday November 08, 2025 @09:25PM (#45862349)
For example , if error data contains string, if it directly point to input string it won't require allocation, but will have memory safety issue if error is passed to outer scope where input string is deallocated. Many errors copy string to make it usable in outer scope.