liveBook · Manning

What you will learn in Systems Programming with Zig

Simple and safe applications, interpreters, and network services

by Garrison Hinson-Hasty · Manning Early Access Program (MEAP)

Chapter by chapter

Chapter 1: Zig’s big ideas

The chapter introduction positions Zig as a systems language for builders and explains the projects and working habits it suits.

1.1 How are we going to learn Zig? · 1.1.1 This is an opinionated book · 1.1.2 LLM usage · 1.2 Zig is C’s collaborator, not C’s successor · 1.2.1 Zig was born into a thriving ecosystem · 1.2.2 Zig’s heritage · 1.2.3 Zig’s improvements on C and C++ · 1.3 Leveling up developer experience, for the users · 1.3.1 Hey, did you forget something? · 1.3.2 Do it at comptime · 1.3.3 Memory is a resource · 1.3.4 Building is not an afterthought · 1.4 Learning Zig without frustration · 1.5 Just Don’t Get Stuck! It’s That Easy · 1.5.1 Read errors before you weep · 1.5.2 Use a debugger · 1.5.3 Use zig fmt · 1.5.4 Explore, don’t copy · 1.6 How does Zig feel? · 1.6.1 All Your Codebase · 1.6.2 Maybe ‘Hello, world!’ isn’t that simple. · 1.7 Applying Zig · 1.7.1 System libraries · 1.7.2 Embedded systems and operating systems · 1.7.3 Servers and daemons · 1.7.4 Compilers, interpreters and language tooling · 1.7.5 Plugins and embedding · 1.7.6 WebAssembly · 1.7.7 Games and game engines · 1.7.8 Desktop and Mobile Applications · 1.7.9 Scientific data wrangling · 1.8 Summary

What you learn in chapter 1 →

Chapter 2: A practical guide

The introduction frames Zig as a pragmatic language and explains why the book teaches basics before moving to practical projects.

2.1 The anatomy of a Zig program · 2.1.1 Variables · 2.1.2 Basic types · 2.1.3 Functions · 2.1.4 Back to modules · 2.1.5 That’s it? · 2.2 Pointing You in the Right Direction · 2.2.1 Single-Item Pointers · 2.2.2 Arrays · 2.2.3 Slicing and dicing · 2.2.4 Buffers and Undefined · 2.2.5 I’ve been Stringing You Along · 2.2.6 A few points to review · 2.3 Structs · 2.3.1 Structs are also namespaces · 2.3.2 Methods, sort of · 2.3.3 Struct initialization in the wild · 2.3.4 Simple and sweet · 2.4 Summary

What you learn in chapter 2 →

Chapter 3: I/O with utility

Introduces cat as a simple, useful program and argues that dependable everyday software is a worthwhile use for Zig.

3.1 Standard Zig · 3.1.1 First and Foremost · 3.1.2 Allocating with Allocators · 3.1.3 Not just I/O · 3.2 Meow, says cat · 3.2.1 Adopting our first cat · 3.2.2 Errors, catch and try · 3.2.3 The interface pattern · 3.3 Giving our cat more toys · 3.3.1 For loops · 3.3.2 Cat but it can concatenate · 3.3.3 While loops · 3.4 Questioning our cat · 3.4.1 All of the cat errors · 3.4.2 Defer to better resource management · 3.4.3 Improvement can be a waste of time · 3.4.4 Making the wheel nuclear grade · 3.4.5 Writer, meet reader · 3.5 Buffering and building with Buff and Bill · 3.5.1 Why do we need build scripting? · 3.5.2 Our build script · 3.5.3 To buffer, or not to buffer · 3.5.4 Say goodbye to our cats · 3.6 Summary

What you learn in chapter 3 →

Chapter 4: Structuring programs, from REPL to webpage

The chapter introduces a word ladder game that will be built first as a REPL and then as a web application.

4.1 Climbing the ladder · 4.1.1 Thinking in comptime · 4.1.2 Comptime caveats · 4.1.3 Executing our plan · 4.1.4 Talk to me · 4.1.5 Core logic · 4.1.6 Check it · 4.2 Wilda’s want for words · 4.2.1 Connecting the web · 4.2.2 A poor conversationalist · 4.2.3 How do I HTTP? · 4.2.4 The HTTP cherry on top · 4.2.5 Modularity makes it easy · 4.3 Next steps · 4.4 Summary

What you learn in chapter 4 →

Chapter 5: A fabulous FFI cookbook

The chapter introduction frames a recipe-book library as a small, reliable solution to a time-pressed programming assignment.

5.1 What makes a recipe book? · 5.2 Learning the lingua franca · 5.2.1 So, what is the C ABI, and why do we care about it? · 5.2.2 What using the C ABI looks like · 5.2.3 Strings without slices · 5.2.4 Enums, a semantic superpower · 5.3 Library construction · 5.3.1 Objectively good design · 5.3.2 Tabling it · 5.3.3 Making it useful · 5.3.4 Recipes should live on for a long time · 5.4 The easy part: C compatibility · 5.4.1 Screaming louder when things go wrong · 5.4.2 Sending over all that data · 5.4.3 Saving and loading · 5.5 What do you think, Tony? · 5.6 Next steps · 5.7 Summary

What you learn in chapter 5 →

Chapter 6: A CHIP-8 interpreter

The chapter introduces CHIP-8 as an interpreter project, explains why building interpreters is valuable, and defines bytecode.

6.1 Let’s put you to work · 6.1.1 Testing with Zig · 6.1.2 So how do you actually write tests? · 6.2 Wait — what is a bytecode interpreter? · 6.2.1 Examining CHIP-8’s design · 6.3 Measure twice, cut once · 6.3.1 Maximizing modularity · 6.3.2 Simplifying with structures · 6.3.3 On your mark, get ready, load and step! · 6.3.4 How do you design programs? · 6.4 Devices for the desktop · 6.4.1 Building with new blocks · 6.4.2 Hello, Window! · 6.4.3 Interactivity · 6.4.4 Running the runtime · 6.5 Time to DIY · 6.5.1 Twiddling bits, not thumbs · 6.5.2 Understanding my guide · 6.5.3 Decoding, nibble by nibble · 6.5.4 Register instructions and overflow operators · 6.5.5 Skipping around · 6.5.6 Power up the stack · 6.5.7 Inputting and outputting · 6.5.8 Writing things · 6.5.9 Saving state · 6.5.10 Ticking along · 6.6 Wait — tell me again what this interpreter is for? · 6.7 Next steps · 6.8 Summary

What you learn in chapter 6 →

Chapter 7: The baroque world of computer graphics

The chapter introduces hardware-accelerated graphics as a visible form of systems programming and explains why working with GPUs is demanding.

7.1 Designed by aliens, for aliens · 7.1.1 Unfortunately, the history of graphics APIs matters · 7.1.2 The rasterization pipeline · 7.1.3 Actually getting access to the pipeline · 7.2 A minimally messy build process · 7.2.1 Translating GLFW · 7.2.2 glad · 7.3 The canvas · 7.3.1 Creating a window with GLFW · 7.3.2 Don’t we care about error handling? · 7.4 Painting with pixels · 7.4.1 Important things with frighteningly vague names · 7.4.2 Going to space · 7.4.3 There is no shader build system · 7.4.4 An object for managing objects · 7.4.5 Vexing vertices · 7.4.6 The payoff · 7.5 Next steps · 7.6 Summary

What you learn in chapter 7 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.