How to read fast
Lesson 4 Reading order
tests, then types and signatures, then core logic, then the rest
What you'll learn
- Read a change in order: tests, signatures, core logic, the rest
- Read a test as a sentence of the spec
- Spot what the tests leave out and tests that were bent to fit
Where you start reading decides how much you understand. Line 1 of the biggest file is almost always the wrong place.
The idea
Read in this order. 1. Tests: they show what the code is meant to do, with real examples. 2. Types and signatures: the names, inputs and outputs, a table of contents. 3. The core logic: the one function that does the real work. 4. The rest: helpers, glue and config, only as far as you need.
Each step makes the next one cheaper: examples, then the outline, then the details. One warning. If the AI wrote the tests too, they show what the AI believes the code does. Read them as a claim, and look for the cases they leave out.
1import test from "node:test";2import assert from "node:assert/strict";3import { applyDiscount } from "./discount.js";45test("SAVE10 takes 10% off", () => {6 assert.equal(applyDiscount(100, "SAVE10"), 90);7});89test("an unknown code changes nothing", () => {10 assert.equal(applyDiscount(100, "NOPE"), 100);11});1213test("the total never goes below zero", () => {14 assert.equal(applyDiscount(15, "TAKE20"), 0);15});
- Line 3 The first thing to take from a test file: the name and the inputs,
applyDiscount(amount, code). - Line 5 Rule 1, as an example: a 100 order with
SAVE10is 90. - Line 9 Rule 2: a code that doesn't exist is not an error, the amount is unchanged.
- Line 13 Rule 3: the floor is zero. Now ask what is not here: a lowercase code, a negative amount, an empty code.
Take away
- Order: tests, then types and signatures, then core logic, then the rest.
- Tests are examples of the intended behaviour; read them first.
- Tests the AI wrote are a claim: look for what they don't cover, and for tests that were edited to pass.
Quiz: test yourself
7 questions: a quick quiz, then a review drill. Pick an answer to see why it's right.