logoalt Hacker News

Zambytetoday at 2:55 PM1 replyview on HN

This language exists so you can reuse the same code in environments where memory allocations may fail, and where memory allocations can't fail.

Let's say you write an application that runs as a Unix daemon in Zig. Later you may decide that your application is really the only thing you're interested in running on the target machine, and for performance and predictability reasons, you'd prefer to boot directly to your application, instead of to an OS that launches your daemon. You can just swap out the implementation of the std.Io runtime for one that targets the hardware directly, instead of a Unix. You don't have to make any changes to your application.

That's kind of an extreme case, but it's the kind of flexibility Zig provides.


Replies

Panzerschrektoday at 3:27 PM

> This language exists so you can reuse the same code in environments where memory allocations may fail, and where memory allocations can't fail.

In my hypothetical example of a language where allocation fails aren't exposed it's possible too. An allocation fail just triggers a full system reboot.