Understanding the Zig Programming Language

Have problems wrapping your head around the Zig programming language? Here is a guide.

Erik Engheim
The Startup

--

So you are curious about Zig but you don’t know exactly where to start. Maybe you read the introduction at the Zig web site, and maybe you even began reading ziglearn.org, but still feel a little lost.

One first stumbling block for people is the idea that Zig is a C-like language:

pub fn readAll(self: Self, buffer: []u8) Error!usize {
var index: usize = 0;
while (index != buffer.len) {
const amt = try self.read(buffer[index..]);
if (amt == 0) return index;
index += amt;
}
return index;
}

But many people looking at the code above will say this doesn’t look very C-like at all. What is up with the pub, and fn keywords e.g.? And what about var in front of variables? That looks like JavaScript!

This means we really have to define what specifically we mean when we say that Zig is a C-like language. A lot of the syntax in Zig is indeed different from C, but what we really means is how the language works. The best way to give a sense of this is to begin by talking about what Zig doesn’t do.

Language Features Zig Doesn’t Have

--

--

Erik Engheim
The Startup

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.