Port and Stash
THE DOORWAY AND THE BOX — a program can't use what it can't keep: Port (I/O) brings information in from the world, and Stash (a variable) holds it in a labeled box until the program calls for it. Take it in, then hold it — input without storage just slips away.
A story read by Port and Stash
Loading audio…
Press play to listen along. The line being read lights up as you go.
Show full transcript
Loading transcript…
The program stood at the edge of the world, and between it and everything outside there was exactly one way through: a doorway, wide and busy, with Port standing right in the middle of it. Port was the doorway, really — the single boundary where the program and the world passed things back and forth. A tapped key, a clicked button, a number typed in, a word spoken aloud: all of it came IN through Port. And whatever the program wanted to send back — a picture, a beep, an answer — went OUT through Port too. "I'm the in and the out," Port said, waving something through. "Nothing reaches the program without coming past me, and nothing reaches the world without going past me either. I'm the I/O boundary. Traffic's my whole life." Beside the doorway, quiet and boxy and patient, sat Stash. "Busy day?" asked Stash. "Always," said Port. "Here — catch."
And this was the thing Port could not do alone, the thing Port had learned the hard, fluttery way: Port could let information in, but Port could not keep it. A number came flying through the doorway — a good number, a needed number — and Port passed it along and reached for the next thing; and if there had been nowhere to put that number, it would simply have slipped away. Gone. Out the other side, unrecoverable. Port's hands were always full of the next thing arriving; Port had no way to hold the last thing at all. "That's the part that used to scare me," Port admitted. "All this coming in, and me unable to hold a single bit of it. Like catching rain in open hands. I can open the door. I just can't keep what walks through it." It is the commonest beginner bug there is: read an input, never store it, and wonder why the program forgot the answer the instant it got it.
But Stash could keep it. Keeping was Stash's entire calm nature. Stash was a variable — a plain labeled box — and the whole point of Stash was to hold a value until it was called for. When Port passed something through, Stash took it, tucked it safely inside, and wrote a name on the front so it could be found again: score, name, count. Whatever it was, Stash held it, steady and unbothered, for as long as the program needed — a second, an hour, the whole run. "You bring it in, I hold it," said Stash, catching the number Port tossed and setting it gently inside. "That's the deal. You're the door; I'm the box — the state. Ask me for it whenever; I'll have it right here, exactly where you left it, name still on the front." And later, when the program did ask — what was that number again? — Stash opened up, and there it was, safe and sound, ready to use.
So they worked the doorway together all day, the pair of them, in a rhythm as easy as breathing. Something came through the door — Port caught it. Port turned and passed it over — Stash held it. The program called for it — Stash opened up and handed it back — Port sent the answer out into the world. In through Port, held by Stash, out through Port again. Read, store, use, respond. Over and over, the whole warm humming day. "Funny how it works," said Port, in a quiet moment between visitors. "On my own I'm just a door with the wind blowing through — everything comes in and everything leaves and I keep none of it." "And on my own," said Stash, "I'm just an empty box with a name on the front and nothing to hold. I can keep anything — but only if somebody brings it to me first." Neither role is the program; both together are how a program remembers what it was told.
By the end of the run, the box was full of exactly the right things — every number, every name, every value the program had needed, each safe in its place with its label facing out — and the doorway stood quiet at last, its long day's traffic all come in and gone back out. "Good catching," said Port. "Good keeping," said Stash. There is a warm, settled feeling in being the one who holds — the one others bring their important things to, trusting you to keep them safe and hand them back whole when the time comes. Port opened the door to the whole wide world; but it was Stash, quiet and boxy and steady, who made sure nothing the program needed was ever lost. Input opens the door. State keeps what walks through it. And a program that can do both — take in, then hold — is a program that can finally remember.
The CodeRealm ensemble
Port and Stash is part of CodeRealm's distributed-narrative cast. Each character embodies a different curricular primitive; together they teach the full subject.
-
Stash
Variable / storage — the labeled box that holds a value until you call for it
-
Fork
Conditional / branching — chooses a path based on what's true right now
-
Trek
Loop / iteration — keeps going around until the work is done
-
Module
Function / encapsulation — does one job well and can be called anywhere
-
Glitch
Debugging / inspection — finds bugs gently, never shaming; 'there's always a reason'
-
Order
Sequence / syntax — reminds you that order matters in code
-
Row
A list: many values lined up in a numbered row, so you can grab item number three instantly or walk through them one by one.
-
Port
Input and output: the doorway that brings information in from the world (a key press, a sensor) and sends results back out.
-
Ping
An event: a waiting bell that does nothing until its trigger happens, then runs its code the instant it is struck.
-
Shuffle
Randomness: a fresh unpredictable value each time — a dice roll, a shuffled deck — so a program can surprise, vary, and stay fair.