
Most high school students treat their code like a long grocery list, simply writing line after line until the program happens to work.
This beginner tendency to create monolithic blocks of instructions is a hard habit to break. When my students sit down for Modular Design in Programming, they usually think that if the computer runs the script, the task is finished. They ignore the fact that one single change can break an entire program if it is not organized well. This high school computer science lesson is built specifically to head off that messiness by teaching students to break complex tasks into smaller, reusable parts called modules.
Refactoring for professional habits
The lesson starts by introducing a scenario where a programmer has to calculate a pizza order: adding the base price, the cost of toppings, and the final tax. If you keep all of that in one block, it becomes difficult to manage. The lesson defines modular design as a programming strategy that breaks a large, complex algorithm into smaller, self-contained units. It is not just about organizing code for the sake of neatness. It is about professional sustainability. Large applications like social media networks rely on this, and no single person could manage those millions of lines of code if they were not separated into manageable pieces.

Students learn through three main vocabulary terms: modular design, function, and encapsulation. By understanding that a function is a named block of code that performs a specific, repeatable task, they stop repeating their own work. The idea of encapsulation, or hiding the internal logic of a function so it can be used without knowing how it works inside, is the key to creating clean programs. Whether you teach in Riverside Unified, Los Angeles Unified, Lucia Mar Unified, or Temple City Unified, the core expectations for student output remain consistent across the state.
Building the computational artifact
The guided practice moves students away from hypothetical examples and into a text-based adventure game. They look at code meant for room descriptions that currently exists as repetitive, clunky segments. By refactoring this room-lookup code into a single function, the students see the immediate value of their efforts. This makes their game, which is a type of computational artifact, much easier to maintain. You can tell your students that a computational artifact is simply any object created by a computer, and making that object professional is a key skill for any future software developer.
The standard served here is CA.CS.9-12.AP.17. This California-adopted standard asks that students create computational artifacts using modular design. It is part of the Algorithms and Programming domain and specifically targets the Modularity cluster. The standard is straightforward: it requires students to demonstrate that they can organize their code into pieces that actually make sense for the bigger project. I find that this is the moment when students stop being mere code-writers and start acting like engineers.
When to use this module
This lesson fits well as a whole-class assignment when you are introducing functions or methods in your syllabus. It is also excellent for a student who missed the week during your unit on control flow, as it provides a clear bridge between basic sequencing and more advanced software architecture. I have also used similar material for a substitute day; it is self-contained enough that students can work through the pizza logic and the text-based adventure game without me having to intervene every five minutes. One caveat: watch for students who try to over-engineer their modules early on. They will want to create a separate function for everything, even simple tasks that do not need them. Encourage them to find the balance between too much abstraction and having a giant, messy script. This lesson does a good job of showing that balance by using the game engine example, where the movement module and the score module are kept separate for a reason.




