Many programs begin the same way: they read command-line arguments, decide what the user requested, then execute an operation.
| Section | Title |
|---|---|
| 1 | A Command-Line Parser |
| 2 | A File Copier |
| 3 | A Line Filter |
| 4 | A Tiny HTTP Client |
| 5 | A Static Library |
| 6 | Testing Strategy |
| 7 | Benchmarking |
| 8 | demo |
| 9 | Where to Go From Here |
| 10 | Appendix A. Zig Syntax Summary |
A Command-Line ParserMany programs begin the same way: they read command-line arguments, decide what the user requested, then execute an operation.
A File CopierA file copier is a useful small program. It opens one file for reading, opens another file for writing, then copies bytes from the first to the second.
A Line FilterA line filter reads text, changes or selects some lines, and writes the result. Many Unix programs have this shape.
A Tiny HTTP ClientAn HTTP client opens a network connection, sends a request, receives a response, and writes the response body.
A Static LibraryA library is code meant to be used by another program. In Zig, a library can be built from the same kind of source files as an executable. The difference is in how the build...
Testing StrategyTests should be close to the code they check. Zig makes this easy with test blocks.
BenchmarkingA benchmark measures the cost of a program or operation. The result is useful only if the measurement is repeatable and the work being measured is clearly defined.
demoA program is finished only when another machine can build and run it reliably.
Where to Go From HereThe programs in this chapter are small, but they have the shape of larger Zig programs.
Appendix A. Zig Syntax SummaryThis appendix summarizes the core syntax of Zig 0.16. It is a compact reference, not a tutorial.