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 need XWhat is X?What must it remember?What can happen to it?What must always hold?ExamplesRepresent the stateWhich structure?Each operationPseudocodeImplement oneTest with examplesEdge casesIntegrate

“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.

Say what you need
beginner
intermediate
advanced

How much help?

Difficulty dial

Every stage's content is shown right after your attempt box.

Booking — twelve stages

I know I need bookings — a meeting room, a seat, a time slot. I have no idea how to implement a booking system.

0 / 12 stages attempted
I need XWhat is X?What must it remember?What can happen to it?What must always hold?ExamplesRepresent the stateWhich structure?Each operationPseudocodeImplement oneTest with examplesEdge casesIntegrate
stage 1 of 12

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?

Your attempt — write before you look

Booking = A claim on one resource for one interval of time, made by someone, which excludes every other claim on that resource during that interval.

Identity, ownership, lifetime
  • Does a booking have identity? Yes. Two bookings of the same room by the same person for the same hour on different days are two bookings; cancelling one must not cancel the other. It needs an id from the first version, because cancel has to name one.
  • Who owns it? The person who made it — the owner is who may cancel it. The resource is owned by whoever manages rooms or seats; the booking only points at it.
  • How long does it exist? From the moment it is made until it is cancelled — or, in history-keeping versions, forever with a cancelled flag. Whether the interval has passed does not delete it; past bookings are the record of what happened.
  • Should it survive reload? Yes, from the first real version. A booking that disappears on restart lets the room be booked twice, which is the one thing the concept exists to prevent.
  • Should it survive login? It is keyed by the owner and the resource, so it is visible wherever the owner logs in; anonymous bookings need a contact instead of an owner, which is a modification.
The principle
If you do not know how to build the thing, make the thing smaller until you reach something you do know how to build. Go one primitive lower →
SIMPLIFIED

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.