There’s a lot to like about Zig vs. Rust, C and C++ (when you do not want garbage collection, or to implement a runtime/GC), even if you do not use Zig as a language, only its compiler and toolchain:
Zig is not just a programming language but also a toolchain that can help you maintain and gradually modernize existing C/C++ projects, based on your needs.
Rust has an advantage with no race conditions, but I think that’s more if your whole project is in Rust, and for Julia’s runtime doesn’t apply. [Of course we want no race conditions in Julia code, or the runtime though.]
https://ziglang.org/learn/why_zig_rust_d_cpp/
No hidden allocations
Zig has a hands-off approach when it comes to heap allocation. There is no new
keyword or any other language feature that uses a heap allocator (e.g. string concatenation operator[1]). The entire concept of the heap is managed by library and application code, not by the language.
Examples of hidden allocations:
- Go’s
defer
allocates memory to a function-local stack. In addition to being an unintuitive way for this control flow to work, it can cause out-of-memory failures if you use defer
inside a loop.
- C++ coroutines allocate heap memory in order to call a coroutine.
[…]
First-class support for no standard library
As hinted above, Zig has an entirely optional standard library. Each std lib API only gets compiled into your program if you use it. Zig has equal support for either linking against libc or not linking against it. Zig is friendly to bare-metal and high-performance development.
It’s the best of both worlds; for example in Zig, WebAssembly programs can both use the normal features of the standard library, and still result in the tiniest binaries when compared to other programming languages that support compiling to WebAssembly.
A Portable Language for Libraries
One of the holy grails of programming is code reuse. Sadly, in practice, we find ourselves re-inventing the wheel many times over again. Often it’s justified.
- If an application has real-time requirements, then any library that uses garbage collection or any other non-deterministic behavior is disqualified as a dependency. […]
- Currently it is pragmatically true that C is the most versatile and portable language. Any language that does not have the ability to interact with C code risks obscurity. Zig is attempting to become the new portable language for libraries by simultaneously making it straightforward to conform to the C ABI for external functions, and introducing safety and language design that prevents common bugs within the implementations.
A Package Manager and Build System for Existing Projects
Zig is a programming language, but it also ships with a build system and package manager that are intended to be useful even in the context of a traditional C/C++ project.
Not only can you write Zig code instead of C or C++ code, but you can use Zig as a replacement for autotools, cmake, make, scons, ninja, etc