Chapter 12
Coding Subprograms
IN THIS CHAPTER
Organizing code via subprograms
Using subprograms in programming languages
Creating a Spirograph-style program using subprograms
Using parameters to make code flexible
As your coder has probably noticed, writing code can result in a long sequence of instructions that can become complicated and hard-to-follow. One key to coding is to simplify code as much as possible, making it efficient and reusable. Efficient means that the program uses only as many commands as necessary to accomplish a task. Reusable means that, for a group of commands that is used more than one time in a program, the group can be defined once and then used many times without writing all the commands each time.
To accomplish these goals, your coder writes subprograms — small chunks of code that form just a part of the program and can be reused simply by naming the subprogram, and invoking its use by calling its name. Using subprograms makes programs more efficient by reducing redundancy (doing the same thing over and over again) and simplifying code.
Subprograms, ...
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