About this guide
Zig Guide Live is a tutorial and cookbook for the Zig programming language. Before this page was published, a machine compiled and ran every code example on the site against Zig 0.18.0-dev.828+9da287565. When you press Run, your browser downloads the same artifact that ran in that check.
Why it exists
Zig has no stable release, and the language still changes. Much of the text about Zig becomes out of date. These changes occurred between the last tagged releases and today:
pub fn main()got a parameter.- Writers became buffered, and you must flush them.
std.fs.Filebecamestd.Io.File, and it now takes anIo.- The
**array-repeat operator was removed completely. ArrayListdoes not hold an allocator now.
Each of these changes breaks the first program in most Zig tutorials that exist.
Usually this failure is silent. An author writes a tutorial against the compiler that the author had. The tutorial is correct for a few months. Then it is wrong, with no visible sign that something changed. A reader who follows the tutorial gets an error message that is not in the text. The reader cannot tell if the reader or the page made the mistake.
This site makes the failure visible. The prose keeps no separate copy of the examples. The pages embed the same files that the build compiles, so a snippet that stopped working cannot be published. When Zig master changes something, the build fails. The fix is to teach the new form, and to say what the old form was. For a reader who comes from an older tutorial, that difference is usually the most useful part of the page.
How it is built
The repository keeps 283 snippets as ordinary.zig files. A build step compiles all of them, and runs the snippets that can run. Then the build step compares their output with a recorded expected result. The site builds only if all of these checks pass, and only then is the site published. The same check runs again every night against a new compiler. Thus the guide proves that it is correct today, not only on the day of the last edit.
For the full mechanism, read how this guide is verified. That page also tells what occurs to the snippets that cannot run in a browser, and to the five snippets that must fail.
Who writes it
Rajesh Pillai writes this guide. It is the work of one person, written with AI assistance and then verified. The build above verifies every code example. A team of engineers verifies the prose before it is published. The machine checks that the code is correct. People check that the explanation is correct.
This guide is not affiliated with the Zig Software Foundation. The official language documentation is at ziglang.org. If the two disagree on a point, the official documentation is correct.
The source is public at github.com/rajeshpillai/zig-guide, with every snippet and the build that checks them. If something here is wrong, anyone can check and correct it in public. See contact.
The same author also makes short riddle and joke videos on YouTube: Riddle Masti. Each chapter ends with one of these videos, and the video plays on the page.
What it is not
- Not a language reference. The guide runs programs, and then explains what they did. If you need the exact rule, use the official reference and the standard library source.
- Not a guide to a tagged release. The code here targets master. On 0.14 or 0.15, much of the code does not build. For that problem, read Migrate from an Older Zig.
- Not stable in the way a book is. The chapters change when the compiler changes. The version in the footer is always the compiler that verified the page that you read. The page what's new lists the new chapters.
- Not published without review. The drafts use AI assistance, but no draft goes on the site for that reason alone. The build proves the code. Engineers read the prose, and they can tell if the explanation is correct.
Reading it
There are seven tracks, and one reading order through all of them. The arrows at the bottom of every chapter follow that order, so you can read the guide from start to end. If you know what you want, the reading paths give a route for seven common starting points. The guide index lists every section.