Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Zig

A small, explicit systems language: no hidden control flow, no hidden allocations, compile-time code instead of macros, and a toolchain that builds and cross-compiles C as well as Zig.

Zig is a general-purpose systems programming language created by Andrew Kelley and first announced in 2016. It aims at the territory of C: operating-system components, game engines, embedded firmware, databases, language runtimes and command-line tools. It keeps C's directness (you decide where every byte lives) while removing much of what makes C hard to get right: there is no preprocessor, no hidden control flow, no hidden memory allocation, and in its safe build modes the compiler inserts checks that turn overflow, out-of-bounds access and many other mistakes into clear crashes instead of silent corruption. Its signature idea is comptime: ordinary Zig code that runs at compile time, which replaces macros and templates. Zig also ships a complete C and C++ toolchain, so it is often used to build and cross-compile existing C projects.

Zig has not reached version 1.0. The language and especially its standard library change between releases, sometimes substantially, and code written for one version often needs updating for the next. This course is written for Zig 0.17.1, the current release as of late 2026, and every program in it was compiled and run with that version. If you use a newer version, expect some standard-library names to differ; the language reference and the standard library source that come with your compiler are the final word. The course assumes the Start level of Lumenary CS or equivalent experience: you know what a variable, a loop and a function are. Knowing a little C helps in places but is not required.

To run the programs, download Zig from the official download page, unpack it anywhere and put the directory on your PATH; the getting-started guide also lists package managers that carry it. Zig is a single download with no other dependencies. There is no official online playground; Compiler Explorer can compile Zig in the browser, though its versions may lag behind the latest release.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 4 lessons

The language

Zig's philosophy and toolchain, values, integer and float types, control flow, arrays, slices, pointers and strings, and structs, enums and tagged unions.

  1. 1First steps with ZigWhat Zig is for, the ideas behind it, and how to install it, run a program and read what the compiler tells you. 45 min
  2. 2Values, types and control flowIntegers of any width, explicit conversions, arithmetic that never silently overflows, and if, switch, while and for as expressions. 55 min
  3. 3Arrays, slices, pointers and stringsFixed-size arrays, the slices that view them, the pointer types between them, and why a Zig string is just bytes. 55 min
  4. 4Structs, enums and tagged unionsGrouping data with structs and methods, naming choices with enums, and modelling "one of several kinds" safely with tagged unions. 60 min

Practice · 3 lessons

Errors, memory and compile time

Error unions with try, catch and errdefer, optionals, explicit allocators and leak detection, and comptime: generic types and functions written in ordinary Zig.

  1. 5Errors and optionalsError unions with try, catch and errdefer, error return traces, and optional values with orelse and if captures. 60 min
  2. 6Explicit allocatorsWhy every Zig function that needs memory asks for an allocator, the allocators in the standard library, and how to use lists and maps without leaks. 65 min
  3. 7Comptime and genericsRunning ordinary Zig code during compilation, treating types as values, and building generic data structures and functions without a separate template language. 65 min

Professional · 2 lessons

Tools, C and a complete program

Test blocks, the build system and packages, calling C and being called from it, and a complete expression calculator in idiomatic Zig.

  1. 8Tests, the build system and CTest blocks and leak-checked tests, build.zig and packages, and Zig's two-way relationship with C, from zig cc to exported functions. 70 min
  2. 9A complete project: an expression calculatorA tokenizer, a recursive-descent parser and an evaluator in idiomatic Zig, with arenas, diagnostics, buffered output and leak-checked tests, and where to go next. 80 min

Further reading and resources