O'Reilly logo

App Inventor by Ellen Spertus, Liz Looney, Hal Abelson, David Wolber

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 21. Defining Procedures: Reusing Blocks

image with no caption

Programming languages like App Inventor provide a base set of built-in functionality—in App Inventor’s case, a base set of blocks. Programming languages also provide a way to extend that functionality by adding new functions (blocks) to the language. In App Inventor, you do this by defining procedures—named sequences of blocks—that your app can call just as it calls App Inventor’s predefined blocks. As you’ll see in this chapter, being able to create such abstractions is very important for solving complex problems, which is the cornerstone of building truly compelling apps.

When parents tell their child, “Go brush your teeth before bed,” they really mean “take your toothbrush and toothpaste from the cabinet, squeeze out some toothpaste onto the brush, swivel the brush on each tooth for 10 seconds (ha!),” and so on. “Brush your teeth” is an abstraction: a recognizable name for a sequence of lower-level instructions. In this case, the parents are asking the child to perform the instructions that they’ve all agreed mean “brush your teeth.”

In programming, you can create such named sequences of instructions. Some programming languages call them functions or subprograms. In App Inventor, they’re called procedures. A procedure is a named sequence of blocks that can be called from any place in an app.

Figure 21-1 is an example of a procedure whose ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required