Zig is Pretty Cool
I've been using Zig recently. It's really, really nice. If you haven't used it, just imagine if C was written today - tackling the same problems, but with many, many years of hindsight on the main pain points of C. It solves a lot of C's problems for me much more graciously than C++ has - and honestly, I only really preferred C++ for the templated container types!
Let me go over why I like it so much:
- Its compile-time evaluation allows for reflection and generic programming, solving many of the same problems as C++'s templates, but without feeling like a separate hacked-on layer atop the actual language. Defining generic types and functions just feels natural!
-
Its
deferstatement makes handling cleanup effortless, much like in Go. In a sense, it kinda serves the same purpose that automatic destructors serve for me in C++ a lot of the time - cleaning up resources when a block is exited - but without all the custom type move-constructor messiness. -
Allocators are a first-class part of the standard library, giving
a lot of control over how just about every function allocates memory.
Imagine if basic C functions like
getlinelet you change their allocators! - It's very, very easy to use C libraries from Zig... Or to integrate Zig code into a C project. Heck, you can even use the Zig compiler as a drop-in replacement for a C compiler!
- Zig naturally supports slices, which are kind of like pointers that also carry a size - making it very easy to prevent a lot of out-of-bounds nonsense that happens constantly in sloppy C.
- The zig build system is really easy to use.
- The standard library has a built-in structure-of-arrays container!
- The creator and lead developer is very clever, politically aware and delivers some excellent talks. Seriously, this guy gives me loads of faith in the language. I trust him to keep this language simple, powerful and just plain good.
Of course, there is one big downside: the language is changing a lot right now. Code and especially build configuration written for the current version of zig (0.15.2 at time of writing) might need to be adjusted or rewritten come the next release. I am perfectly fine with this - the language is already great, and there is little harm in keeping old projects on old versions. For big projects that need long-term stability, maybe wait for version 1.0 - just please don't pressure the developers to push out 1.0 early. Let them cook! It's going great!
Thank you for coming to my, uh, zed talk?