2.4 Procedures

Enduring Understanding

      • Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Essential Questions

      • How can we store data in a program to solve problems?

      • What might happen if you completed the steps in your regular morning routine to get ready and go to school in a different order? How might the reordering affect the decisions you make each morning?

      • How do video games group different actions for a player based on what key is pressed on the keyboard or controller? How do apps group different actions together based on user interaction, such as pressing buttons?

      • What types of problems can be solved more easily with a computer, and what types can be solved more easily without a computer? Why?

Lesson Objectives

  1. For procedure calls:

    • Write statements to call procedures.

    • Determine the result or effect of a procedure call.

  2. Explain how the use of procedural abstraction manages complexity in a program.

  3. Develop procedural abstractions to manage complexity in a program by writing procedures.

  4. Select appropriate libraries or existing code segments to use in creating new programs.

Essential Knowledge

  1. A procedure is a named group of programming instructions that may have parameters and return values.

  2. Procedures are referred to by different names, such as method or function, depending on the programming language.

  3. Parameters are input variables of a procedure.

  4. Arguments specify the values of the parameters when a procedure is called.

  5. A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing. Once the last statement in the procedure (or a return statement) has executed, flow of control is returned to the point immediately following where the procedure was called.

  6. One common type of abstraction is procedural abstraction, which provides a name for a process and allows a procedure to be used only knowing what it does, not how it does it.

  7. Procedural abstraction allows a solution to a large problem to be based on the solution of smaller subproblems. This is accomplished by creating procedures to solve each of the subproblems.

  8. The subdivision of a computer program into separate subprograms is called modularity.

  9. A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for program code reuse, which helps manage complexity.

  10. Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.

  11. Using procedural abstraction helps improve code readability.

  12. Using procedural abstraction in a program allows programmers to change the internals of the procedure (to make it faster, more efficient, use less storage, etc.) without needing to notify users of the change as long as what the procedure does is preserved.