Putting It All Together: The Event Chain Let us bring together everything from this series and see events, listeners, and responses working as a complete, connected system. What You Learned Post The Big Idea ------ ------------- What is an Event? Something that happens — a tap, a timer, a sensor — that a program can notice and respond to Events Are Everywhere Smoke alarms, automatic doors, phone notifications — real-world events you experience every day Events Inside Programs Programs set up event listeners; when an event fires, the matching response commands run A Complete Example: The ATM Machine An ATM machine is a perfect example of an event-driven system. It does almost nothing on its own — it waits and responds to events. Here is the full event chain from the moment you walk up: Event 1: Card Inserted Trigger: Physical card slot sensor detects a card Event: Card inserted Response: Read card data → display PIN entry screen → start listening for the next event Event 2: PIN Entered Trigger: User presses the "Enter/Confirm" button after typing 4 digits Event: PIN confirmed Response: Send card number + PIN to bank → wait for authentication response → start listening for the next event Event 3: Authentication Response Received Trigger: Bank server sends back a success or failure message Event: Authentication result received Response: If failure: show "Incorrect PIN" → listen for retry or cancel If success: show account menu → listen for user choice Event 4: User Selects "Withdraw Cash" Trigger: User taps the "Withdraw" option Event: Withdraw option selected Response: Show amount selection → listen for amount Event 5: Amount Confirmed Trigger: User enters an amount and presses Confirm Event: Withdrawal amount submitted Response: Check balance → if sufficient, dispense cash → print receipt → eject card Every single thing the ATM does is triggered by an event. Between events, it waits. When an event fires, a decomposed sequence of precise commands runs. Did you know? The world's first cash machine opened outside a Barclays bank in Enfield, London, in 1967. There were no plastic cards — you fed it a special paper voucher, and the machine kept the voucher. What Connects All Three Series Look at how the ideas from the last three series connect: Series Concept How It Appears in the ATM --- --- --- Commands Specific instructions "Send card number + PIN to bank server" Decomposition Breaking big goals into steps Authentication → menu → selection → dispensing — each decomposed Events What triggers the steps Card inserted, PIN confirmed, button tapped, server responded Commands are the individual steps. Decomposition organises them into sequences. Events trigger those sequences to run at the right moment. Together, they describe almost every interactive program ever built. The Event Chain, Drawn Simply Something happens (event) > → Program is listening (event listener) > → Correct response runs (decomposed sequence of precise commands) > → Program returns to listening > → Something else happens... This is the heartbeat of every interactive program. What is Still Missing? You can now describe events, break down responses, and write good commands. But there is one idea that will make all of your instructions even more reliable: precision . A command like "check if the balance is enough" is still vague for a computer. Enough for what? How much is "enough"? Exactly how should the check work? When instructions are not precise enough, even well-structured programs produce wrong results. Writing instructions that are exact — no gaps, no ambiguity — is its own skill. And it is what the next series is about: Instructions Must Be Clear: The Art of Precision. 🎯 Try This Yourself Sabotage the ATM All you need is five cards — scraps of paper will do — a pen, and one other person. 1. Write the five ATM events from this post on the five cards, one per card: card inserted , PIN entered , bank replied , withdraw chosen , amount confirmed . On the back of each card, write its response. 2. Lay the cards face up in a row. That is your event chain. 3. Turn your back. Your partner secretly sabotages it in one of three ways: turn a card face down (that listener has stopped listening), swap two cards over (the events now arrive in the wrong order), or take a card away completely. 4. Turn round and walk the chain out loud as if you were the machine: "Card in. Now I am listening for a PIN…" Work out where it goes wrong and, more importantly, what the person standing at the machine would actually see happen . 5. Swap roles and go again. What to watch for: each sabotage breaks in its own way. A face-down card makes the machine freeze — it waits forever for an event nobody is listening for. A swap makes it ask for money before it knows who you are. A missing card makes it skip a step it must never skip. Real bugs feel mysterious from the outside, but almost all of them are one of these three: nobody listening, the wrong order, or a missing step.…