A Year of Zig ⚡

by Nick Salvatore

I've decided to commit to learning Zig for the next year or so. The rationale is pretty simple: I want to work in a language that allows me to build real software without unnecessary headaches but also forces me to learn how computers really work and what high-level languages abstract away.

I just got started yesterday, reading Chapter 1 of Introduction to Zig ↗ and tackling the Hello World ↗ exercise on Exercism. Hello World exercises usually feel like a joke, especially on Exercism. They hand you a function that says "Goodbye, Mars!" and you modify the text to say "Hello, World!" Run the tests. Pass. Done. And to be clear, that's exactly what the Zig exercise was, but there was enough unfamiliarity in the function signature for me to pause and dig into it more.

The point of this post isn't to educate, but to illustrate my point briefly—and it's a dumb point—here's the hello() function:

pub fn hello() []const u8 {
    return "Hello, World!";
}

Coming from Python and Go, if I return a string in a function, my return type is something like str or string, not []const u8. I looked up what a u8 type is: unsigned 8-bit integer. So the return type is a slice of const (?) of unsigned 8-bit integers. Why would a slice of integers be the return type for a string? Why const? I wrote the questions I had down, then researched until I could answer each one. As I said, the point of this isn't to explain all of this. The point is that this is the first Hello World exercise I've encountered where I wasn't just learning about language-specific syntax to make a program do what I want it to do. Obviously, Zig is not alone in this, but it nevertheless excited me to have a simple exercise push me deeper into the computer.

So yeah, I'm looking forward to this next year.