Core · 05/05 5 min
Building from a spec
How to approach implementation labs: interfaces first, edge cases early, tests as the contract.
Build labs are the opposite of debugging: the tests describe a component that doesn't exist yet.
- Read every test name before writing code. They are the requirements list. Group them: happy path, validation, edge cases, errors.
- Write the skeleton: exported names, method signatures, return shapes. Run the tests: the failures should now be about behaviour, not "is not a function".
- Happy path first, then validation, then edge cases. Re-run after each step; watch the count of green climb.
- Choose data structures deliberately. LRU → Map (insertion order) or hash map + doubly-linked list. Leaderboard → sorted structure or heap. Rate limiter → per-key timestamps or counters.
- Keep state private and return copies, so callers can't mutate internals.
- Error contract: throw specific errors or return specific status codes exactly as the tests expect.
Treat the test file as the API doc. If a test expects
201and{ id }, that's the spec, even if you'd design it differently.
Practise it now
Next in Core
The debugging playbook