Zig is the Next Big Programming Language

Zig is an amazing programming language that has the potential to become huge in the coming years. Learn more about Zig and why you should consider using it.
Saturday, May 11, 2024

What is Zig?

Zig is a general-purpose programming language designed for performance, safety, and simplicity. It aims to provide modern features while remaining lightweight and efficient. Developed with a focus on readability and robustness, Zig offers compile-time memory safety, error handling without exceptions, and predictable behavior. It supports various platforms, making it suitable for multiple application domains.

What that means is that Zig is a language that is designed to be easy to read, write, and maintain, all while having a comparable performance and efficiency to C, with a few modern features that make it a joy to work with. I’ve been using Zig for a few years now (since 2020) and I’ve been loving it. It’s been my go-to language for a lot of my hobby projects, server-side applications, and even some zany web dev projects that I have running on my home network.

Can Zig Replace C?

That is hard to say, personally, I think it’s entirely possible because zig is also a drop-in compiler for C and C++. You can use Zig to compile your C and C++ code without ever needing to use GCC, Clang, or MSVC. This means all C and C++ code can be compiled and even interop with Zig.

How does Zig manage memory?

Zig has a very unique way of handling memory allocation, which is drastically different from the approach that Rust took. With zig, you have full control over how you allocate your memory and how you deallocate it. That means you have arena allocation, page allocation, general allocation, etc. You can even create your own custom allocation, and together with comptime access, you can even make a custom allocator that will automatically deallocate memory when it goes out of scope, which may be super familiar to a lot of you Rust devs out there.

When does Zig outshine Rust?

The performance of Zig and Rust is pretty much neck and neck, that is to say, the differences in performance are negligible. However, Zig has a lot of cool features that Rust does not and most likely never will, such as the ability to compile C/C++ interop with C and C++ code, consume C and C++ libraries, manual memory management, comptime which is similar to Rust macros but much more powerful and straightforward.

So I wouldn’t say it’s a matter of Zig outshining Rust, but rather Zig being a different tool with a different approach to solving problems. An approach that I find much more enjoyable and straightforward than Rust.

Can Zig compile C++?

Yes as mentioned above one of Zig’s biggest strengths is its ability to compile C++ and C code.

Can Zig be used for embedded systems?

I’ve used Zig on my Raspberry Pi and it’s been a joy to work with. Now I know that a Raspberry Pi is not strictly the same as proper embedded systems programming, but it’s at the very least comparable. Basically, if you can run C on it you can run Zig on it for the most part. So yes Zig can be used for embedded systems programming.

Zig vs Go

Much like Go Zig is a systems programming language, but unlike Go Zig is a low-level language that gives you full control over memory allocation and deallocation. Go on the other hand is a garbage-collected language that does not give you that level of control. There are a lot of situations where Garbage collection is too slow or too inefficient or simply does not fit the use case. If that is your current use case then Zig would be a much better choice than Go. Of course on the other hand Zig is at the time of writing this article still not stable and nowhere near as mature as Go, so do take that into consideration.

Zig vs C++

Zig is a much simpler language than C++. While it also builds on the same principles as C++ and allows you to allocate and deallocate memory manually just like C++, it does not have the same level of complexity that C++ has. Zig is designed to be a modern language that is easy to read, write, and maintain. C++ has been around for a while and powers some of the biggest and most vital applications in the world. But it is not without its flaws, one of which that I specifically dislike is how many different ways you have to achieve what is essentially the same thing. Zig on the other hand is much more straightforward. Also, Zig does not have nor will ever have classes, so if OOP is something you can’t live without then Zig may not be for you.

But it’d still urge you to try it and experience a paradigm shift. I know I did and I’ve never looked back.

When will Zig be stable?

That is hard to say, the Zig team is working hard to get Zig to a stable release, but as of writing this article, it is still in version 0. something. So it’s hard to say when it will be stable. But what I can tell you is that you can already write a heck of a lot of stuff with Zig.

Does Zig have a package manager?

No Zig does not currently have a package manager, one is planned and actively worked on and will most likely be released sometime in 2024. But for now, we sadly have to manually manage our dependencies.

Does Zig have async?

No Zig at the moment of writing this article does not have async, but it is planned and actively worked on. So it’s only a matter of time before Zig has async. Also as a side note, you can write your Zig applications out as multiple binaries and use the GNU scheduler to run them concurrently, which does a much better job than most async implementations in other languages, give it a try you may be pleasantly surprised.

Why should I use Zig?

Zig is a fantastic modern language that is a joy to use and work with. It reads wonderfully and gives you the developer complete autonomy over your entire application including how you will manage your memory. Instead of managing your memory behind the scenes, it gives you the tools and the power to do that yourself. I find this approach of teaching instead of enforcing much better and even more secure than Rust’s approach of enforcing strict memory safety by having the developer jump through hoops. Not to mention that it’s still entirely possible to write memory-unsafe code in Rust it’s painfully easy to do so.

So use Zig if you want a modern, performant, and memory-safe language that is actively developed by a team of incredibly talented developers

Is Zig hard to learn?

Zig the language itself is not hard to learn, I’d even say it’s surprisingly simple. The main difficulty comes from the fact that Zig is a low-level systems programming language, so you will have to understand some core Computer Science concepts and have a good low-level understanding of how your system works. But if you are willing to put in the time and effort to learn Zig you will be rewarded.

Conclusion

Zig is a fantastic language that I’ve loved using and will continue to use I will most likely write about it a lot more in the future. It’s a language that I enjoy working with and I firmly believe it has a bright future and a lot of potential to become a major player in the programming language space. With this article, I hope I’ve given you a good overview of what Zig is and why you should consider using it and hopefully answered some of the questions you may have had about Zig. If you have any more questions feel free to reach out on Twitter, I’m always happy to help out and chat.

Wanna show support?

If you find my sporadic thoughts and ramblings helpful.
You can buy me a coffee if you feel like it.
It's not necessary but it's always appreciated. The content will always stay free regardless.