Day 11 - Introduction to Functions
Day 11: Introduction to Functions
Learning Objectives
- AAP-3.A: For procedure calls: Write statements to call procedures.
- AAP-3.B: Explain how the use of procedural abstraction manages complexity in a program.
Essential Questions
- How do functions help us organize and reuse code?
- What is procedural abstraction and why is it important in programming?
Materials Needed
- Presentation slides on functions and procedural abstraction
- Programming environment
- Function implementation worksheet
- Code refactoring examples
- Exit ticket templates
Vocabulary
- Function
- Procedure
- Method
- Procedural abstraction
- Modularity
- Call
- Definition
- Implementation
- Reusability
Procedure (50 minutes)
Opening (8 minutes)
-
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
-
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)
-
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
-
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
-
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)
-
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
-
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
- Formative: Quality of function implementation during hands-on activities
- Exit Ticket: Effectiveness of program organization using functions
Differentiation
For Advanced Students
- Challenge them to identify more opportunities for abstraction
- Introduce the concept of function composition
- Discuss advanced topics like recursion (preview)
For Struggling Students
- Provide function templates to complete
- Focus on simpler functions with clear purposes
- Use visual aids to illustrate function execution flow
Homework/Extension
- Complete a worksheet with function implementation exercises
- Refactor a previously written program to use functions
- Research how functions are used in professional software development
Teacher Notes
- Emphasize that functions are a fundamental concept in programming
- Watch for confusion between function definition and function call
- Make connections to mathematical functions students already know
- Consider using analogies like recipes or instruction manuals
- Remind students that good function design is key to maintainable code