Zig is a general-purpose systems programming language designed by Andrew Kelley. The language bills itself as “a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software”. Proponents of Zig often argue that the language is a revolutionary low-level language that represents a massive shift in how you think about programming. They claim it’s the best C replacement language. This is high praise indeed, so let’s see if it can actually live up to the hyperbole. Philosophy Its core philosophy emphasises explicit control: the language motto is “No hidden control flow”. In practice, this means all memory allocation, error handling, and control-flow constructs must be spelled out by the programmer. Kelley has stressed that the language is for creating “optimal” solutions at the cost of some programmer inconvenience. Correctness and robustness are equally held as important goals for Zig code. Critics argue that Zig adding undefined behaviour compared to C for additional possible compiler optimisation benefits runs counter to these last two goals, although the Zig documentation claims they are not in opposition: “Zig uses undefined behavior as a razor sharp tool for both bug prevention and performance enhancement.” link At the same time, even Zig’s docs acknowledge that ReleaseFast and ReleaseSmall have no protection against UB that isn’t detected when testing with Debug or ReleaseSafe.* From this, we can conclude that the Zig approach is to assume that all undefined behaviour will be caught while testing in safe mode, and the application can then safely be run without checks and with full performance in production. This is different from most other languages that either retain many checks, or at least try to retain well-defined behaviour as much as possible. * EDIT: On the Zig discord there was some resistance to this saying ReleaseSafe was a good alternative to be used in production to ensure safety. However, since this has a ...
First seen: 2025-05-11 13:22
Last seen: 2025-05-11 14:22