Chapter 6
Breaking a Large Program into Subprograms
IN THIS CHAPTER
Using a subprogram
Passing parameters
Using recursion
The bigger the program, the harder that program is to read, fix, and modify. Just as it’s easier to spot a spelling mistake in a recipe printed on a single page than it is to find that same spelling mistake buried inside a 350-page cookbook, it’s easier to fix problems in a small program than it is in a big one.
Because small programs can perform only simple tasks, the idea behind programming is to write a lot of little programs and paste them together, like building blocks, creating one massive program. Because each little program is part of a much bigger program, those little programs are subprograms, as shown in Figure 6-1.
FIGURE 6-1: Every large program is made ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
The biggest problem with dividing a large program into multiple subprograms is to make each subprogram as independent, or loosely coupled, as possible. That means if one subprogram fails, it doesn’t wreck the entire program along with it, like yanking out a single playing card from a house of cards.