In this chapter
We'll learn the difference between comments and documentation, the kinds of documentation a team keeps — from function docs to architecture notes, decision records, runbooks and changelogs — and how to write them so they stay useful, explained as notes in a cookbook's margin versus the cookbook itself.
The Problem in Real Life
Two of the 31 comments are different. One asks: "Why does the student discount apply after the group discount and not before?" The other, from Samantha's sales manager, asks: "Where can I read the pricing rules in plain English? Venues keep asking me."
Anna realises neither question can be answered with better names. The first needs a comment. The second needs documentation. "They're different things," John says, "for different readers."
Code says how. Comments say why. Documentation says how to use it and how it all fits together.
John
Knowledge in One Person's Head vs. Written Where Readers Will Find It
The "why" disappears
Code shows what happens, but the reason for a decision is lost unless someone writes it down.
Different readers
Developers, the sales team and on-call engineers each need different information.
Docs go stale
Documentation that's out of date sends readers in the wrong direction.
Comments vs. Documentation, and the Kinds of Documentation
The cookbook analogy: a chef's notes in the margin of a recipe — "add the salt late, or the sauce splits" — help the next cook at exactly that line. The cookbook itself — the introduction, the chapter on techniques, the index — helps someone who wants to learn how to cook from it, without reading every recipe. Code comments are the margin notes. Documentation is the cookbook.
- Comments — notes in the margin (Act 07): a comment sits next to the code and explains why: a business reason, a surprising decision, a workaround and its link. If a comment only repeats what the code does (
// add 1 to count), the code should be clearer instead. A wrong comment is worse than none, so update comments when the code changes. - Documentation — the cookbook: documentation explains, separately from the code, how to use something or how the system fits together. It's for readers who won't — or shouldn't have to — read the code.
- Function and API docs — the label on each tool: a short block above a public function describing its purpose, parameters, return value and errors, often in a standard format (JSDoc, Python docstrings). Editors show it when you hover over the function. API docs for other teams (Act 23, OpenAPI) are the same idea at a larger scale.
- README — the front door (Act 16): what this project is, how to set it up, run and test it, and where to find everything else.
- Architecture docs — the map: how the parts of the system connect: diagrams like Anna's Sale Day diagram (Act 14), what talks to what, where data lives.
- Decision records — why we chose this: an ADR (architecture decision record) is a short note: the situation, the options, the decision and its consequences. "Why do we use cursor pagination?" (Act 23) — answered once, forever.
- Runbooks — what to do at 3 AM: step-by-step instructions for operating the system and handling incidents: "if the email queue is older than 5 minutes, do this" (Act 21).
- Changelogs and release notes — what changed: a list of changes per version (Act 18), for users and other developers.
- Keeping docs alive: keep docs in the repository, next to the code, and update them in the same pull request as the change (Act 16). Write for a specific reader, put the most important thing first, use examples, and delete docs that are no longer true.
| Question | Where the answer belongs | Reader |
|---|---|---|
| Why is this line like this? | Comment | The next developer at this line |
| What does this function take and return? | JSDoc / docstring | Developers calling it |
| How do I set up and run this project? | README | New developers |
| How do the parts fit together? | Architecture doc | Developers, new team members |
| Why did we choose X over Y? | Decision record (ADR) | Future team members |
| The queue is stuck at 3 AM — what now? | Runbook | On-call engineer |
| What changed in v2.4.0? | Changelog / release notes | Users, other developers |
| How do group prices work? | Plain-English doc | Sales team, venues |
/*** Calculates the total price for a group booking.** @param {number} ticketCount - Number of tickets (1–60).* @param {number} basePrice - Price of one ticket.* @param {boolean} isStudent - Whether the group is a verified student group.* @returns {number} Total price after any group and student discounts.*/function calculateGroupPrice(ticketCount, basePrice, isStudent) {// ...// Student discount applies AFTER the group discount, as agreed with venues// (pricing decision, 2026-09). Applying it first would over-discount large groups.}
Anna's two answers: for the developer's question, a comment above the student rule: // Student discount applies after the group discount, as agreed with venues (pricing decision, 2026-09). Applying it first would give larger groups a bigger total discount than intended. For the sales manager, a short doc, docs/pricing-rules.md, written in plain English, with a table of every rule and three worked examples — and a link to it from the README. The sales manager replies: "Printing this and putting it on the wall."
Key Takeaway
Comments are notes in the margin: they sit by the code and explain why. Documentation is the cookbook: it explains how to use something and how the system fits together, for readers who won't read the code — function docs (JSDoc, docstrings), the README, architecture docs, decision records, runbooks and changelogs. Keep docs in the repo, update them in the same pull request, write for a specific reader, and delete what's no longer true.
Why This Matters
Good documentation multiplies a team's speed: fewer interruptions, faster onboarding, safer operations at 3 AM. Juniors who write clear docs and useful comments are noticed quickly — and knowing which kind of writing belongs where is a skill many experienced developers never learn.
29 comments left. Anna works through them — and realises that reviewing and being reviewed are skills in themselves. Meanwhile, her own bug report to the mobile team has just come back with two words: "Can't reproduce."
