Zig by Example

Hacker News Top Tools

Summary

A hands-on introduction to the Zig programming language via annotated examples, covering basic to advanced topics. Inspired by Go by Example.

No content available
Original Article
View Cached Full Text

Cached at: 06/08/26, 03:17 PM

boringcollege/zig-by-example

Source: https://github.com/boringcollege/zig-by-example

Zig by Example

License: CC BY 4.0

A hands-on introduction to Zig via annotated examples. Zig is a general-purpose, compiled systems language focused on robustness, optimality, and simplicity — no hidden control flow, no hidden allocations, no preprocessor.

Written by Dariush Abbasi for Boring College


  1. Hello, World
  2. Values
  3. Variables
  4. Integers
  5. Floats
  6. Strings
  7. Arrays
  8. Slices
  9. Vectors
  10. Structs
  11. Enums
  12. Unions
  13. Functions
  14. Blocks and Statements
  15. If / Else
  16. Switch
  17. While Loops
  18. For Loops
  19. Defer
  20. Errors
  21. Optionals
  22. Pointers
  23. Multi-Pointers
  24. Slices (Pointers)
  25. Comptime
  26. Generics
  27. Memory Allocation
  28. ArrayList
  29. HashMap
  30. Linked List
  31. Testing
  32. Formatting and Print
  33. File I/O
  34. Processes
  35. JSON
  36. Random Numbers
  37. Sorting
  38. Math
  39. Build System
  40. C Interop

Further Reading


Zig by Example is inspired by Go by Example by Mark McGranaghan. Examples target Zig 0.14.

Contributions welcome — see CONTRIBUTING.md.

Similar Articles

Zig by Example

Lobsters Hottest

Zig by Example is a hands-on introduction to the Zig programming language, featuring annotated example programs for version 0.16.

The Zig Journey

Lobsters Hottest

The blog post reflects on attending Zigtoberfest and provides tiered advice for using the Zig programming language, focusing on systems thinking, design depth, and software perfection.

Returning to Zig

Lobsters Hottest

The author describes their journey from Zig to Rust and back to Zig, exploring the trade-offs between stability and expressiveness in programming languages.

What Zig felt like, coming from Rust

Lobsters Hottest

An experienced Rust developer shares their journey of learning Zig by reimplementing a JSONPath tool, highlighting differences in IDE support and code organization.

Zig: From Beginner to Slightly Less Beginner

Lobsters Hottest

In his Zig talk at Code Maven, Sawyer X uses examples of configuration parsing and memory allocation to explain Zig’s core design philosophy: everything is visible, there is no hidden control flow, there are no macros or operator overloading, and problems should be turned into compile-time errors whenever possible.