Earlier quoted context omitted.
Zig is in the space of languages where an abstraction that decides that memory allocations are irrecoverable is not good enough. If you work in an environment where memory allocations can't fail or can't be handled if they fail, you might not want to use Zig, or C for that matter. Not every language should be designed to live in the space of "somehow low level but also a good choice for your basic web backend", like…
> If you work in an environment where memory allocations can't fail or can't be handled if they fail, you might not want to use Zig, It's most of environments. Basically any program running under a modern OS. So, why do this language exists, if its practical applicability is so small?
Zig Zen Update
61–65 of 65 posts
Re: Zig Zen Update
#62Earlier quoted context omitted.
You can certainly write data structures in Zig that swallow allocation failures rather than surfacing them. We're talking about library-level concerns, not language-level concerns. Both Rust and Zig give you the power to allocate raw memory and handle the result of that syscall however you want, it's the standard libraries that differ beyond that point.
Yes, it is a standard library difference. But unless you plan on rewriting the entire Rust ecosystem, you're going to be dealing with invisible failure points in Rust code that you would not be dealing with when writing the equivalent Zig code. The standard library is almost as fundamentally important to a language as it's built-in operators. And Zig does have language-level features that combine to require you to ex…
That's what Rust's libcore is for. And the converse is that if your software is written for a system with overcommit--so every typical OS and distro these days--any error path having to do with memory allocation failure is impossible to trigger, because the OS won't honestly tell you if allocation would fail.
> And Zig does have language-level features that combine to require you to explicitly handle propagated errors
Of course, and Zig also doesn't stop you from writing a data structure that papers over allocation failures by using `std.process.exit` in the error path. Zig also discourages third-party dependencies more than Rust does, so I wouldn't be surprised if people are already wisely doing this when writing their code for programs targeting systems with overcommit.
Re: Zig Zen Update
#63Earlier quoted context omitted.
On modern OSs you can write Zig and just ignore allocation errors. It doesn't force you to handle them properly. This language exists to supercede or supplement C, not JavaScript or C#. It's practical applicability is similar to that of C, so I struggle to comprehend how it is "so small".
> On modern OSs you can write Zig and just ignore allocation errors. I can ignore errors, but I still need to free memory manually if I want to avoid memory leaks. Languages like C++ or Rust have destructors, which do the job for me. > This language exists to supercede or supplement C There are way better alternatives, like Rust. Even C++ is better.
Re: Zig Zen Update
#64Earlier quoted context omitted.
> On modern OSs you can write Zig and just ignore allocation errors. I can ignore errors, but I still need to free memory manually if I want to avoid memory leaks. Languages like C++ or Rust have destructors, which do the job for me. > This language exists to supercede or supplement C There are way better alternatives, like Rust. Even C++ is better.
Zig has defer, your point is quite invalid.