I Know What I Need, But I Don't Know How To Build It
Pick the thing you need. Then derive it: meaning, state, operations, rules, examples, representation, pseudocode — and only then the code, one rung at a time.
“I know I need a shopping cart. I have no idea how to implement a shopping cart.” The gap is not a missing tutorial; it is a missing method. Every stage below asks you to write before it shows you anything, because the code is the last step of a derivation, not the first thing to search for.
Which concept?
Grouped by exercise level; the level is how far the derivation goes, not how hard the code is.
How much help?
Every stage's content is shown right after your attempt box.
Cache — twelve stages
I know I need a cache in front of a slow lookup. I have no idea how to implement a cache.
Define the concept
In one sentence, without any code: what is it? Then answer for yourself — does it have identity, who owns it, how long does it exist, should it survive a reload or a login?
Cache = A bounded, temporary copy of values that are expensive to fetch or compute, kept so repeated reads of the same key can be answered without going back to the source.
- Does a cache have identity? No. A cache is defined by what it stands in front of, not by its contents; two caches over the same source are interchangeable, and any cache can be emptied at any moment without losing information. That is the property everything else follows from.
- Who owns it? The code that reads from the slow source — the cache sits between that reader and the source. Whoever writes the source owns invalidation, which is why "the writer deletes the key" is a rule and not a feature.
- How long does it exist? Each entry lives until it expires, is evicted to make room, or is deleted by a writer. The cache as a whole lives as long as the process (V1) or the cache server (V2); either way it can be thrown away.
- Should it survive reload? Usually not; a cold cache is slow, not wrong. Persisting a cache trades a warm start for the risk of serving values that the source changed while the process was down.
- Should it survive login? A cache does not know about users unless the key does. A value computed for one user must be keyed by that user, or the next user reads it — a security rule, not a caching one.
The catalog is one derivation, not the only one (impl §60). A different set of examples yields different rules; a different first requirement yields a different V1; a map instead of an array is not wrong, only an answer to a different question. Compare your derivation with the reference for the differences, then decide which ones were rules and which were style.
Take it further
The flagship exercise: the cart typed by you, with the reference hidden until you ask.
Make It Smaller Until You Know How to Build It →The principle behind the ladder, and the primitive chain it produces.
The Implementation Loop →The loop the twelve stages follow, and why the code is last.