Chapter 12

Coding Subprograms

IN THIS CHAPTER

check Organizing code via subprograms

check Using subprograms in programming languages

check Creating a Spirograph-style program using subprograms

check 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, ...

Get Helping Kids with Coding For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.