Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix C: From Empty Directory to Installed

The book in one table per stage, for a program of your own. Each row is a step, what it produces, and the chapter that explains it. The steps are in the order ved took them, adjusted where ved’s order turned out to be wrong.

C.1 Before any code

StepProducesChapter
Write the one-sentence descriptionA sentence to test every later decision against1
Find the external specification: a standard, a file format, an existing programAnswers to “what should this do?” that are not opinions1
Write the decision table, including what the program will not doConstraints that answer questions in advance1
Slice by capability, each slice a working programA plan that can stop at any point and leave something usable1
cargo new, then fill in every metadata field in Cargo.tomlA manifest that can be published without edits1, 17
Decide where reasoning goes: commit messages, not sourceA repository that describes the present1, 16

C.2 Building it

StepProducesChapter
Make main return an ExitCode, and parse arguments strictlyExit statuses scripts can rely on2
Make the command function return a value describing what to doA command language testable without a terminal2
Put each invariant behind a module boundaryState that only a few methods can change3
Keep one place where 1-indexed meets 0-indexed, and return Option for user-supplied positionsNo off-by-one at the boundaries, no panic on a typo3
Separate parsing from resolvingErrors reported against the right cause4
Let each command choose its own defaultNo flag parameters on a shared function4
Index strings by character, never by a literal byte offset into input you did not inspectNo panic on the first non-ASCII character5
Build replacements before swapping them inA failed operation that leaves the old state intact5, 13
Hard parts first in isolation, with their own tests, before wiring them inAn engine that can be trusted when it is connected7, 8, 9
Keep marks, cursors, and positions attached to the things they refer toLoops that survive the operations they perform12
Treat input from files as foreign: line endings, encodings, missing final newlinesFiles that come back the way they went in13

C.3 Saying what happened

StepProducesChapter
Write every message in the user’s terms as the command is writtenNo sweep at the end5, 14
Route each kind of output through one functionA consistent voice, and a plural that is right everywhere14
Distinguish requested output, confirmations, and errors in the typesA -s flag that is one line in the loop14
Exit non-zero when a non-interactive run had an errorScripts that can detect failure14
Reject what you do not understand, in flags, suffixes, and argumentsTypos that fail instead of meaning something else10, 11, 14

C.4 Checking it

StepProducesChapter
Unit tests at the command boundary, asserting on state, not wordingA suite that does not fight message changes15
One integration test per responsibility of the outer loopCoverage of the layer unit tests cannot see15
Expected values from the specification, never from running the codeTests that can disagree with the code15
A differential harness against the reference implementationThe disagreements nobody thought to test15
A fuzzer over the input languageThe crashes nobody would type on purpose15
A benchmark of the data structure at ten times the expected sizeA measured boundary instead of a feeling15
cargo fmt --check, cargo clippy -- -D warnings, cargo test in CIA gate between a laptop and a release17
Build on the declared minimum Rust version as well as stableA rust-version that is true17

C.5 Writing it down

StepProducesChapter
README in the order of the reader’s questions: what, why, install, start, referenceThe interface for everyone who is not you16
Every terminal session captured from a real run, and re-run when the program changesDocumentation that cannot teach a command that does not exist16
Module comments in the present tense; history in commit messagesComments that stay true16
Each fact stated once, and every other place pointing to itSeven descriptions that cannot disagree16, 18
A manual pageman working after apt install18
A backlog sorted by why each item is not doneDecisions that are not re-argued19

C.6 Releasing it

StepProducesChapter
Pick the version by what changed for users, including behavior and outputA number that means something17
Run everything checkable before the tagNo release that needs an immediate patch17
Write the release notes from typed commit subjectsA release page that says what changed16, 17
Tag, build every target, publish checksumsA release anyone can download and verify17
Publish to crates.iocargo install17, 18

C.7 Getting it to people

StepProducesChapter
A Makefile whose install does not buildsudo make install that works18
A .deb with correct depends, and a signed apt repositoryapt install, apt upgrade, and authenticity18
A WinGet manifest generated from Cargo.tomlwinget install, with a description that matches18
Add each channel only when someone needs it, with a way to tell whether they still doChannels you can afford at every release18
When a channel ends, say so where its users will lookUsers who know where to go next19

C.8 After

StepProducesChapter
Read the program closely, as if writing a book about itThe findings the tests missed19
Put each finding in the tracker the day it is madeFindings that get fixed19
Stop data loss with a small fix first, then fix the designA safe place to make the large change19
Delete backlog items when they ship, and recheck the reasons on the restA backlog that describes what is left19
Decide which reference wins when the specification, the original, and the implementation on your machine disagreeBug reports nobody argues with20
Fix one issue per commit, test first, with the expected value from the referenceA history that reads as the list of fixes21
Run the harness and the fuzzer after the last fix, not the firstThe bugs the fixes made21
Write commit subjects that survive being turned into release notesNotes that say what changed, in the user’s terms22
Close an issue when users can see the fix, not when the code has itA tracker that says what is still wrong for users22