Module

FUNCTION / ENCAPSULATION — *does one job well and can be called anywhere.*

Loading audio…

Press play to listen along. The line being read lights up as you go.

Show full transcript

Loading transcript…

01 Opening
Module beat 1 of 5

Module wasn't furry or feathery. Module was a box — a small painted box with a label on the front that told you exactly what it did. On its left side was a slot for inputs; on its right side, a slot where outputs came out. Loop always said it best: "Module does one thing. And it does it well."

"Alright, class — today we meet Module!" Loop clapped her hands. Module sat on a little stand, its label reading Add_Sparkle. "See that? That's Module's name. It tells you its job." She held up a plain grey pebble. "And this is our input."

02 Module
Module beat 2 of 5

Loop dropped the pebble into Module's left slot. Thunk. A soft whirring came from inside, like a tiny happy bee — then ping! — and a pebble rolled out the right slot, no longer grey but shimmering with tiny rainbow sparkles. "Output!" Loop cheered. "A sparkly pebble!" She held up another plain pebble. "What'll happen?" "Sparkles!" someone shouted — and thunk, whirr, ping, out came another. "Exactly. Same input, same output, every time. And here's the cool part — you can use Module anywhere. At the park. On the moon! As long as it gets an input, it gives you an output." She mimed tucking it in a backpack. "Ready whenever you need it."

03 Module
Module beat 3 of 5

"Now look closely," Loop said. "Can you see inside?" Everyone squinted. "Nope!" "That's the magic! You don't need to know how Module adds sparkles — only that it does. The inside is hidden. It's Module's secret." She grinned. "And why is that good? Because if I swapped out Module's whole secret sparkle-machine for a better one, you'd never know — you'd still drop in a pebble and still get a sparkly pebble out." "It just works," a kid whispered. "Exactly. It just works. That's a good function — and keeping its insides tucked away where they can't trip you up? That's called encapsulation."

04 Module
Module beat 4 of 5

"Now imagine a big job," Loop said, waving her arms. "A whole galaxy of sparkly planets! You could try to do it all at once — but that'd be messy and hard. Instead, you break it down: use Module for one planet, then the next, then the next. Each small job makes the big job easier." She tapped the label. "And if you had a thousand pebbles to sparkle — would you build a thousand sparkle-machines?" "No way!" "Right — you build Module once, and call it a thousand times, or a million, just by its name: 'Hey Module — Add_Sparkle this!' No rewriting the steps." She picked up an already-sparkly pebble and dropped it back in — thunk, whirr, ping — out came one so bright it glowed. "See? One function can even use another function's output — or call another function from inside itself. That's how you build truly amazing things."

05 Closing
Module beat 5 of 5

"One last thing — names," Loop said, tapping the label. "Add_Sparkle — see how it's a doing-word, like 'run' or 'jump'?" She wrote on the board: calculateTotal() — "this calculates a total" — and isValid() — "this asks, is it valid?" "A function's name should tell you what it does, or what question it answers. You wouldn't name Module just 'Pebble' — that only says what it works on, not its job." She smiled and held up her fingers. "So remember Module — a function. Inputs in, output out, one job, call it anywhere. Break big problems into small pieces — that's modularity. Build it once, use it many times."

And here's the feeling Loop most wanted you to have. That moment when a job feels way too big — a whole galaxy, a thousand pebbles — and your chest gets tight and you don't know where to even start. And then you remember Module: just one small piece, done well, and I can reuse it. Break the giant thing into little one-job boxes, and the tightness loosens, and the impossible galaxy becomes just one planet at a time. That calm, I-can-actually-do-this feeling when a huge job breaks into small pieces — that's the quiet reward of a good function. Chase that.

The CodeRealm ensemble

Module is part of CodeRealm's distributed-narrative cast. Each character embodies a different curricular primitive; together they teach the full subject.

Kids also liked