Day 11 - Introduction to Functions

Day 11: Introduction to Functions

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Week 3 Introduction (3 minutes)

    • Review nested control structures from previous lesson
    • Introduce Week 3 focus on functions and procedural abstraction
    • Connect to today's focus on functions as a way to organize code
  2. Warm-up Activity (5 minutes)

    • Present a program with repeated code segments
    • Ask students to identify the repetition and discuss problems with this approach
    • Introduce the need for code reuse and organization

Main Activities (32 minutes)

  1. Lecture: Functions and Procedural Abstraction (12 minutes)

    • Define functions/procedures as named groups of programming instructions
    • Explain the concept of procedural abstraction:
      • Separating what a function does from how it does it
      • Hiding implementation details
      • Creating reusable code components
    • Discuss the benefits of using functions:
      • Code reuse
      • Readability and organization
      • Modularity
      • Easier testing and debugging
      • Collaboration
    • Introduce function terminology:
      • Definition vs. call
      • Implementation
      • Scope
    • Explain the basic structure of functions in pseudocode:
      • PROCEDURE name()
    • Discuss the flow of execution when calling functions
    • Explain how function calls interrupt sequential execution
  2. Demo: Defining and Calling Functions (8 minutes)

    • Walk through examples of defining simple functions
    • Demonstrate how to call functions from different parts of a program
    • Show the execution flow when functions are called
    • Illustrate how functions can be called multiple times
    • Demonstrate how functions can make code more readable
    • Show before-and-after examples of code with and without functions
  3. Hands-on: Creating Simple Functions (12 minutes)

    • Students work in the programming environment
    • Guide students through creating and using functions
    • Have students implement functions for tasks like:
      • Calculating area or perimeter
      • Converting units
      • Generating formatted output
      • Validating input
    • Encourage students to call their functions multiple times with different scenarios

Closing (10 minutes)

  1. Activity: Refactoring Code to Use Functions (5 minutes)

    • Provide students with a program that has repeated code segments
    • Students refactor the code by creating appropriate functions
    • Compare the original and refactored versions
    • Discuss improvements in readability and maintainability
  2. Exit Ticket and Preview (5 minutes)

    • Students write a program that uses functions to organize code
    • Preview that next class will focus on function parameters and return values

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes