Skip to content

Functions and ModularityActivities & Teaching Strategies

Students retain modular programming best when they physically break tasks into parts and rebuild them. Active learning forces them to confront misconceptions like automatic execution and parameter misuse through hands-on practice. This approach transforms abstract definitions into lived experience.

Grade 9Computer Science4 activities30 min50 min

Learning Objectives

  1. 1Design a program that decomposes a complex problem into at least three distinct functions.
  2. 2Analyze the impact of passing different arguments on function output and program behavior.
  3. 3Evaluate the readability and maintainability of code before and after refactoring into functions.
  4. 4Create a set of interconnected functions to simulate a simple real-world process, such as a basic transaction system.

Want a complete lesson plan with these objectives? Generate a Mission

45 min·Pairs

Pair Programming: Task Decomposition

Pairs get a complex task like a grade calculator. They list needed functions, write and test one at a time, passing parameters for inputs. Switch roles every 10 minutes and integrate at the end.

Prepare & details

Explain how functions improve code readability and maintainability.

Facilitation Tip: During Pair Programming: Task Decomposition, circulate and ask each pair to label every repeated code block with a temporary comment before converting it to a function.

Setup: Flexible workspace with access to materials and technology

Materials: Project brief with driving question, Planning template and timeline, Rubric with milestones, Presentation materials

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
50 min·Small Groups

Small Groups: Modular Shape Drawer

Groups plan a program drawing patterns with functions for shapes, colors, positions. Each member codes one function, then combine, test inputs, and present variations.

Prepare & details

Design a program that breaks down a complex task into multiple functions.

Facilitation Tip: In Small Groups: Modular Shape Drawer, provide a checklist of three required functions (e.g., drawShape, changeColor, resize) to keep groups focused on modular design.

Setup: Flexible workspace with access to materials and technology

Materials: Project brief with driving question, Planning template and timeline, Rubric with milestones, Presentation materials

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
30 min·Individual

Individual: Refactor Challenge

Provide linear code for a simple game. Students identify reusable parts, rewrite as functions with parameters, test old vs new versions, and note improvements in a log.

Prepare & details

Evaluate the benefits of passing parameters to functions for increased flexibility.

Facilitation Tip: For Individual: Refactor Challenge, give students a flawed starter file with global variables and require them to add parameterized functions before any new features.

Setup: Flexible workspace with access to materials and technology

Materials: Project brief with driving question, Planning template and timeline, Rubric with milestones, Presentation materials

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
35 min·Whole Class

Whole Class: Function Share-Out

Students write one utility function, like sorting numbers. Share via projector, class tests with different parameters, discusses reusability and edits live.

Prepare & details

Explain how functions improve code readability and maintainability.

Facilitation Tip: At Function Share-Out, record common patterns on the board and ask students to vote on which refactoring made the code most readable.

Setup: Flexible workspace with access to materials and technology

Materials: Project brief with driving question, Planning template and timeline, Rubric with milestones, Presentation materials

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making

Teaching This Topic

Start with concrete examples—students draw shapes or calculate areas—before introducing formal definitions. Avoid lectures longer than five minutes; instead, use live coding where you model mistakes and fix them. Research shows students grasp scope best when they debug global variable conflicts in real time rather than memorizing rules.

What to Expect

Successful students will articulate why functions improve readability, refactor a linear script into reusable blocks, and explain the difference between functions with and without return values. They will also demonstrate debugging strategies when parameters or globals cause unexpected results.

These activities are a starting point. A full mission is the experience.

  • Complete facilitation script with teacher dialogue
  • Printable student materials, ready for class
  • Differentiation strategies for every learner
Generate a Mission

Watch Out for These Misconceptions

Common MisconceptionDuring Pair Programming: Task Decomposition, watch for students who define a function and expect it to run immediately without a call statement.

What to Teach Instead

Ask pairs to insert print statements before and after the function definition and after each call to visualize when execution occurs.

Common MisconceptionDuring Small Groups: Modular Shape Drawer, watch for groups that rely on global variables for color or size instead of parameters.

What to Teach Instead

Provide a starter file where globals cause a bug, then guide groups to replace them with parameters and observe the fix.

Common MisconceptionDuring Individual: Refactor Challenge, watch for students who assume every function must return a value.

What to Teach Instead

Ask students to add a print-only function to their refactored program and trace its output in a loop to see side effects without returns.

Assessment Ideas

Quick Check

After Pair Programming: Task Decomposition, display a linear script on the board and ask students to write the function definition for the first repeated block before the next activity.

Exit Ticket

During Function Share-Out, collect refactored programs and ask each student to write one sentence explaining how parameters improved their code compared to the original.

Discussion Prompt

After Small Groups: Modular Shape Drawer, pose the question: 'How would adding a new shape feature differ in your modular program versus a single long script? Discuss with your group and summarize in two sentences on the exit ticket.'

Extensions & Scaffolding

  • Challenge: Add a function that draws a pattern using nested loops, then refactor it to accept parameters for pattern type and size.
  • Scaffolding: Provide pre-written function shells with parameter placeholders and color-coded comments for argument matching.
  • Deeper exploration: Introduce default parameters and demonstrate how optional arguments affect function calls in a multi-function program.

Key Vocabulary

Function DefinitionThe block of code that specifies what a function does, including its name, parameters, and the statements it executes.
Function CallAn instruction to execute the code within a defined function. This involves providing any required arguments.
ParameterA variable listed inside the parentheses in the function definition, acting as a placeholder for values that will be passed into the function.
ArgumentA value passed to a function when it is called. This value is assigned to the corresponding parameter within the function.
ModularityThe principle of breaking down a large program into smaller, independent, and interchangeable parts or modules (functions).

Ready to teach Functions and Modularity?

Generate a full mission with everything you need

Generate a Mission