Looking into Odin and Zig
Odin language creator here.<p>Thank you to the author of the article for taking the time to try out both Odin and Zig.<p>I want to clarify my position as the comments you are commenting on are lacking a little nuance.<p>For the first one regarding OOM, Odin&#x27;s allocators all support error values signalling things such as `Out_Of_Memory`, `Invalid_Pointer`, `Invalid_Argument`, and `Mode_Not_Implemented`. So if you you want to handle those error states, there is nothing preventing you from doing so in Odin. However, there are two aspects to my original argument: you should know the constraints of the platform you are on and plan accordingly as it is part of your problem; what happens in the case when you have completely ran out of memory (globally&#x2F;system-wide)?<p>&gt; My reaction to that is “640KB is enough for everything”, right?<p>I&#x27;ve worked on systems with 16KiB and that&#x27;s just how much you had to deal with. Meaning we had to plan accordingly for what we needed so that we never ran out of memory. The program was heavily tested (both analyzed and empirically) so that we made sure that it ran within the constraint of 16 KiB. On such platforms, `malloc` was never called, and in fact banned.<p>&gt; I have never had a program cause a system to run out of memory in real software (other than artificial stress tests).<p>In this comment, I say &quot;program&quot; and not _allocator_ here. I have many allocators that run out of memory _on purpose_. On desktop applications that I have worked on (I know this does not apply to all), if we did run out of memory, the better option is to just crash rather than try to recover. But of course some applications cannot do this, especially when dealing with third-party programs, such as databases (as you state). In those cases, the best you can do is empirically test how much is required and gracefully handle those cases when you do OOM (if possible). That&#x27;s part of your problem, it&#x27;s not an external thing. If you can control things, try to.<p>Minor note: Zig&#x27;s allocators only return one possible error value `error.OutOfMemory`, whilst Odin has 4 possible error values meaning there is a finer granularity in Odin with its error value system for its allocators.<p>Onto the second comment you bring up regarding error value handling.<p>&gt; ...My code, which is calling the service, need to be able to handle any &#x2F; all of those<p>Yes. And you should handle them accordingly, and not just in a general &quot;catch all&quot;, especially since these are wildly different kinds of failure states.<p>&gt; ...Odin relies on the multiple return values system. We have seen how good that is with Go. In fact, one of the most common issues with Go is the issue with how much manual work it takes to do proper error handling.<p>Regarding error value propagation, I needed to clarify my position a little more in that article I was referring to an aggregate set of comments from a GitHub post and not a truly nuanced argument. Odin has the `or_return` operator which allows the user to easily propagate values in code. It is similar to Rust&#x27;s `?` or Zig&#x27;s `try` but complements Odin&#x27;s multiple return values AND does not rely on having a concept of an &quot;error value type&quot;.<p>Demo of `or_return` &lt;<a href="https:&#x2F;&#x2F;github.com&#x2F;odin-lang&#x2F;Odin&#x2F;blob&#x2F;fd256002b3190076bb91ec3e02ae17c858222eb5&#x2F;examples&#x2F;demo&#x2F;demo.odin#L2030" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;odin-lang&#x2F;Odin&#x2F;blob&#x2F;fd256002b3190076bb91e...</a>&gt; And check out Odin&#x27;s [`core:math&#x2F;big`](<a href="https:&#x2F;&#x2F;github.com&#x2F;odin-lang&#x2F;Odin&#x2F;tree&#x2F;master&#x2F;core&#x2F;math&#x2F;big" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;odin-lang&#x2F;Odin&#x2F;tree&#x2F;master&#x2F;core&#x2F;math&#x2F;big</a>) which has big extensive use of the concept.<p>Even though I added this concept to Odin, I do believe that my general hypotheses are still correct regarding exception-like error value handling. The main points being:<p>* Error value propagation _ACROSS_ library bounds
* _Degenerate states_ due to type erasure or automatic inference
* Cultural lack of partial success states<p>The most important one is the degenerate state issue, where all values can generate to a single type. It appears that you and many others pretty much only want to know if there was an error value or not and then pass that up the stack, writing your code as if it was purely the happy path and then handling any error value. Contrasting with Zig, Zig has a built-in concept of an error value type, and all error values are either inferred `!`, have specific error set, or degenerate to `anyerror`. In practice from what I have seen of many Zig programmers, most people just don&#x27;t handle error values and just pass them up the stack to a very high place and then pretty much handle any error state as they are all the same degenerate value: &quot;error or not&quot;. This problem occurs in Go code too because everyone degenerates to the error interface in practice, therefore it&#x27;s now equivalent to a fancy boolean.<p>For error values in Odin, you can use any data type you require for your problem, and even compose many together. It&#x27;s very common to just use an `enum` or even a boolean, but sometimes you need something more complex or aggregate too. A good example of this is when you need to aggregate different possible error values from multiple different data types. The two common approaches are to make a mapping procedure to convert them to the specific `enum` OR to have a (discriminated) `union` of the `enum`s. This means Odin does not suffer from the degenerate state issue that Zig, Go, and many other languages do suffer from. This is because Odin doesn&#x27;t have a built-in degenerate type which would be typically used for error values.<p>One issue with Zig&#x27;s approach is due to its error value inference system, it&#x27;s very difficult to know what possible errors values a procedure returns just from __reading__ the code (assuming `!T` or `anyerror!T` is used), you have to compile the code in order to determine that. This may be okay for a single developer, but if you are on a larger team you are now either relying on external documentation (which Zig can provide) or the compiler telling you this. With a specific (error) set this is not a problem because it&#x27;s explicit to the reader.<p>Most of the time you are reading code, not writing code.<p>Odin&#x27;s type system and feature set is rich enough that you can achieve everything you want _extremely cleanly_. You can many parallels between Odin and Zig: `errdefer` would be akin to `defer if err != nil {` in Odin, `try` would be akin to `or_return`, etc.<p>n.b. Someone recently wrote an article which is closer to my own position on error value handling (with some of the author&#x27;s own flair and preferences) here: &lt;<a href="http:&#x2F;&#x2F;tuukkapensala.com&#x2F;files&#x2F;software_does_not_contain_errors.txt" rel="nofollow">http:&#x2F;&#x2F;tuukkapensala.com&#x2F;files&#x2F;software_does_not_contain_err...</a>&gt;<p>Thank you again for writing this article. And as I always say, I highly recommend people try out as many tools (which includes programming languages) as they can to find what are the best tools for your problems!<p>Regards,<p>Bill