It’s number of new programming languages here. Let’s look at Zig and check what features it offers and how it basically looks. So, Zig is a new language on the market, still having version 0.14.1. No GC here, strong static typing, really small size of compiled binaries. Positioned as a replacement for C. We will begin from pros and cons tnd then will try to code on it a bit.

Pros:

  • Readability. Zig haven’t complex constructions. It’s definitely not Java or C++, or especially Rust.
  • Comptime. Wide opportunities in optimization and metaprogramming.
  • Manual memory management. You control everything by yourself. No hidden memory allocations or any control flows. At the same time it has an interesting system for allocators manipulating.
  • C compatibility. It allows you to not just use libraries written on C and C++, but compile your c/C++ code on the Zig compiler.

Cons:

  • This is a new language. It means no big established communities. Tons of production ready libraries for any taste and color are not available as well but it is compensated by the possibility of using an incredibly big base of C/C++ libraries.
  • Manual memory management. But wait, it already was in the pros section! So, let’s be honest with ourselves, most developers don’t need it at all. In most cases people wanna have GC and don’t take care about memory.
  • Syntacs. This is an absolutely subjective criteria. For me Zig looks way better than, for example, Rust, but not as good as Go. Personal choice of everyone, maybe you will love it.
  • Poor concurrency mechanisms out of the box. It’s important for me and Zig is definitely not a Go with his goroutines and channels. Anyway, you are not limited and in Zig you can implement many things by yourself and even make it significantly faster than in other languages.
  • Vendoring system. Not intuitive and overloaded. You will be frustrated when you see it for the first time.

But it is better to see the code once than read tons of my expressions about the language. I will skip the part about installation of the environment because if you can’t do it by yourself using the official website, I can only politely recommend you to thing about trying yourself in something else. We will try some basic constructions in Zig and will understand how it works.

Of course, let’s make the “Hello World!”, it’s no overview without this example…

Nothing so difficult… Importing looks a bit strange from the first view but it’s ok. The function “main” is a standard entry point, like in many other languages. “!void” means the function will not return nothing meaningful. About types we will talk in next example.

Nothing special as well, right? If you have any experience in other languages, such as C, C++, Go, Rust, and many others - it shouldn’t confuse you. What I personally don’t like - it’s “name first then type” format… Again… What’s wrong with modern langs??? I will not explain the printing section, again, if you have experience with other languages, it will be very intuitive for you in this example.

As a last thing, let’s see how functions work here and we will done for today. Next time we will go a bit deeper.

Nothing special again and yes, “input-output” values are not reversed here. The function simply receives two i32 integers and returns its multiplying result (in i32 again). Very generic format. Your homework: try to guess why we are using “void” instead of “!void” in the main function. Error handling is skipped in this example.

Summary. Not bad so far, very interesting language. I will definitely try to write some exercises on it. I’m sure it’s not the last article about Zig here and next time we will try to make something applicable and useful for testing key features of the language. Stay updated!