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

For those specialized cases, just have your function emit an error/ok type union and early exit with the error information.


If the standard library doesn’t do follow that convention, then it doesn’t matter what I do in my code. I won’t get the information I need from the standard library, and third party libraries are unlikely to follow this ad hoc convention. I’m certainly not willing to rewrite the entire world to follow this ad hoc convention.


You make a good point that the standard library could make better use of this pattern to show it off, but the language was designed with this sort of thing as an affordance and there even is a (rough) example in the docs: https://ziglang.org/documentation/master/#Tagged-union

You wouldn't have to rewrite the world, but the language is young and maybe more effort could go into making using this pattern more idiomatic and encourage library writers to do it more often.




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

Search: