Notes From the Field: Learning Zig

Open on Substack · Markdown

This was my week off and I wanted to learn some more Zig. What I did: dug into the Zig compiler, wrote toy programs to replicate parts of it, tried to understand the Zig way of doing things. I’ve also spent two days hacking a GTK feature into Ghostty, which is largely written in Zig. Feature is not done yet (god no), but it’s probably been the most serious Zig coding I’ve done so far.

So I figured I’d send you some early, rough, subjective thoughts on learning Zig. This is not a comprehensive analysis of Zig and reasons for or against learning it. It’s thoughts that went through my head this week while writing Zig.

 const Person = struct {
     age: u8,
 };

 fn newPerson(age: u8) Person {
     // BUG: This field name is wrong
     //         vvvvvvvvvv
     return .{ .ageInYears = age };
 }

 test "newPerson" {
     const std = @import("std");
     try std.testing.expectEqual(5, 5);
 }

Note the bug. ZLS, the Zig language server, doesn’t tell me there’s a problem and Zig happily compiles and runs this test:

φ zig test lazy.zig
All 1 tests passed.

Why? Because the newPerson function isn’t called in the test.

Again: this probably trips only me up because lack of understanding of comptime. (Told you: not an expert-analysis, but raw, dumb thoughts)

Last thought after this week off and also probably related to Zig: I love programming very much.