Chapter 9: Building Real Projects
Sections 91--100 Everything you have learned comes together. Build libraries, tools, servers, and parsers.
Previous chapters covered C's building blocks and Auto's safer alternatives. Now it is time to build real software. This chapter walks through complete projects -- from small libraries to CLI tools, HTTP servers, and text parsers.
Each section presents both the C approach (what you would write manually) and the Auto approach (what you write instead). By the end, you will have the patterns to build your own projects.
91. Designing Small Libraries
A good library has a clear API, minimal dependencies, and composable building blocks.
C library pattern:
- Header file (
.h) declares the public API - Implementation file (
.c) contains the logic - Prefix all names to avoid collisions (e.g.,
vec2_add,vec2_length)
/* vec2.h */
typedef struct { float x; float y; } Vec2;
Vec2 vec2_new(float x, float y);
Vec2 vec2_add(Vec2 a, Vec2 b);
float vec2_length(Vec2 v);Auto library pattern:
- Types group related data
- Methods on types provide the API
modanduseorganize modules
type Vec2 { x float, y float }
fn Vec2.new(x float, y float) Vec2 { ... }
fn Vec2.add(a Vec2, b Vec2) Vec2 { ... }
fn Vec2.length(v Vec2) float { ... }Auto's method syntax keeps APIs clean. The type name acts as a namespace, replacing C's manual prefixing convention.