Skip to content
Computer Science · Grade 9

Active learning ideas

Functions and Modularity

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.

Ontario Curriculum ExpectationsCS.HS.AP.8CS.HS.CT.9
30–50 minPairs → Whole Class4 activities

Activity 01

Project-Based Learning45 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.

Explain how functions improve code readability and maintainability.

Facilitation TipDuring 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.

What to look forPresent students with a short, linear script (e.g., calculating area and perimeter of multiple rectangles). Ask them to identify repetitive code blocks and suggest how they could be turned into functions. Then, have them write the definition for one proposed function.

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
Generate Complete Lesson

Activity 02

Project-Based Learning50 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.

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

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

What to look forProvide students with a simple program that uses functions. Ask them to trace the execution flow, writing down the value of a specific variable after each function call. Include one question: 'What would happen if you removed the argument from this function call?'

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
Generate Complete Lesson

Activity 03

Project-Based Learning30 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.

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

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

What to look forPose the question: 'Imagine you are working on a team project and need to add a new feature to an existing program. How does using functions and modularity make this task easier or harder compared to a single, long script? Discuss specific examples.'

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
Generate Complete Lesson

Activity 04

Project-Based Learning35 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.

Explain how functions improve code readability and maintainability.

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

What to look forPresent students with a short, linear script (e.g., calculating area and perimeter of multiple rectangles). Ask them to identify repetitive code blocks and suggest how they could be turned into functions. Then, have them write the definition for one proposed function.

ApplyAnalyzeEvaluateCreateSelf-ManagementRelationship SkillsDecision-Making
Generate Complete Lesson

A few notes on teaching this unit

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.

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.


Watch Out for These Misconceptions

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

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

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

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

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

    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.


Methods used in this brief