While most new languages are racing to add features that allow for more concise code, Zig takes the opposite approach: the goal is to read a piece of code and know exactly what the machine will do, with nothing happening behind the scenes.
No covert distribution
Any function that requires dynamic memory must take an allocator as a parameter. It may sound cumbersome, but on the other hand, you can tell just by looking at the function signature whether it uses dynamic allocation—which is very important for embedded software and kernel code.
This also makes it easy to test for memory leaks: pass data to a tracked allocator, and at the end of the test, check to see if anything is left over.
No hidden control flow
No exceptions, no operator overloading, no implicit constructors. Errors are returned as values and must be handled. When reading Zig code, every point where the program can branch to another location is visible.
Run the code immediately upon compilation
Zig allows standard Zig code to be executed during compilation, which is used for type generation, lookup tables, and platform-specific branching. Instead of learning a separate macro language, you use the language itself.
Who should keep an eye out
Zig is not yet stable; its syntax varies across versions, and its library ecosystem is still limited. You shouldn't rely on it for mission-critical systems just yet.
But there’s one thing you can use right away, even if you don’t write a single line of Zig: its toolkit cross-compiles C and C++ to multiple platforms very efficiently, and many projects use it simply to replace their build toolchains.
Thảo luận