This post kicks off a series about the Zig programming language, following the “learning in public” approach I mentioned in my about section.

At least for now, I’m not planning to write long posts or detailed tutorials. Instead, I’ll share my small (but hopefully consistent) steps on this journey. Here and there, I’ll connect some concepts to ones I’m already familiar with from languages like C and Rust.

Language features

As noted in its documentation, Zig serves two main purposes:

  • It’s a general-purpose programming language.
  • It’s a toolchain for building robust, optimized, and reusable software.

Zig is strongly typed and compiled. It supports generics and has compile-time metaprogramming capabilities (we’ll dive into that later). Plus, it doesn’t include a garbage collector.

The code is easy to read and communicates clearly to both the compiler and other programmers. You can use the same source code across different environments with various constraints, and it handles edge cases—like running out of memory—correctly.

Zig standard library

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

First look at the syntax

The code below was taken from the excellent Learning Zig site. The post goes into detail about each line, so I won’t get into that right now. My main goal here is to give you a quick glimpse of the language.

 1const std = @import("std");
 2
 3pub fn main() void {
 4	const user = User{
 5		.power = 9001,
 6		.name = "Goku",
 7	};
 8
 9	std.debug.print("{s}'s power is {d}\n", .{user.name, user.power});
10}
11
12pub const User = struct {
13	power: u64,
14	name: []const u8,
15};

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 working with the last two, and I’m really enjoying them. Ziglings are exercises designed to guide your learning by having you fix small broken programs. They seem to be inspired by Rustlings (from Rust, as you might guess) and are very well structured.

That’s it! We’ve given a quick overview of Zig.