This post starts a series related to the Zig programming language, following the learning in public process that I mentioned in the about section.

At least at the beginning, I don’t intend to create long posts or extensive tutorials. I’ll write down my small (but consistent, hopefully) steps in this journey. Here and there, I’ll try to relate some concepts with similar ones from programming languages that I’m already familiar with, as C and Rust.

Language features

As said in its own documentation, Zig is, at the same time:

  • a general purpose programming language
  • a toolchain for maintaining robust, optimized and reusable software

Zig is strongly typed and compiled. It supports generics, has compile-time metaprogramming capabilities (we’ll talk more about that latter) and does not include a garbage collector.

The code is easy to read and communicates precisely to both the compiler and other programmers. The same source code works in many environments which have different constraints, and behaves correctly even for edge cases, such as out of memory.

Zig standard library

The Zig standard library has its own documentation. It contains commonly used algorithms, data structures, and definitions to help you build programs or libraries.

First look at the syntax

The code below was copied from the excellent Learning Zig site. The post explains the details of each line of code, so I won’t talk that much about them for now. The main goal here is just to show a glimpse of the language.

const std = @import("std");

pub fn main() void {
	const user = User{
		.power = 9001,
		.name = "Goku",
	};

	std.debug.print("{s}'s power is {d}\n", .{user.name, user.power});
}

pub const User = struct {
	power: u64,
	name: []const u8,
};

If you save the above as ssj.zig and run zig run ssj.zig, you should see: Goku's power is 9001.

Learning resources

I’ve started with the last two and I’m really enjoying them. Ziglings are exercises that guide your studies by making you fixing tiny broken programs. It seems to be inspired by Rustlings (from Rust, as you might guess) and it is very well structured.

That’s it. We’ve done a very brief presentation of Zig.