Lesson 4: Debugging in Maze
50 minutes
Overview
In this skill-building lesson, students will encounter pre-written code that contains mistakes. They will need to step through the existing code to identify errors.
Purpose
Students in your class might become frustrated with this lesson because of the essence of debugging. Debugging is a concept that is very important to computer programming. Computer scientists have to get really good at facing the bugs in their own programs. Debugging forces the students to recognize problems and overcome them while building critical thinking and problem solving skills.
Standards
AP - Algorithms & Programming
- 1A-AP-09 - Model the way programs store and manipulate data by using numbers or other symbols to represent information.
- 1A-AP-11 - Decompose (break down) the steps needed to solve a problem into a precise sequence of instructions.
CS - Computing Systems
- 1A-CS-03 - Describe basic hardware and software problems using accurate terminology.
Agenda
Objectives
Students will be able to:
- Modify an existing program to solve errors.
- Predict where a program will fail.
- Reflect on the debugging process in an age-appropriate way.
Preparation
- Play through the puzzles to find any potential problem areas for your class.
- (Optional) Pick a couple of puzzles to do as a group with your class.
- Review *CS Fundamentals Main Activity Tips - Lesson Recommendations.
- Review the *Debugging Guide from this course's curriculum overview page with the class.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- CS Fundamentals Main Activity Tips - Lesson Recommendations
- CSF - Course C - Slides 2022-2023 - Slides (Download)
- Debugging Guide - Resource
For the students
- Pair Programming - Video
Vocabulary
- Bug - Part of a program that does not work correctly.
- Debugging - Finding and fixing problems in an algorithm or program.
- Persistence - Not giving up.
Teaching Guide
Warm Up (15 minutes)
Reflect
Display: Show “Reflect” slide
Ask students to think about problems they have to solve in everyday life.
Reflect:
- How do you fix something in your everyday life that isn't working?
- Do you follow a specific series of steps?
Vocabulary
Display: Show “Vocabulary” slide
This lesson has three new and important vocabulary words:
-
Bug - Part of a program that does not work correctly.
-
Debugging - Finding and fixing problems in an algorithm or program.
-
Persistence - Not giving up.
Persistence works best when you try things many different ways, many different times.
Introduction
Display: Show “Debugging in Maze” slide
Remarks
The puzzles in this unit have already been solved for you (yay!), but they don't seem to be working (boo!) We call the problems in these programs "bugs," and it will be your job to "debug" them.
Display: Show “Debugging” slide
Say: Do you see an error in your program?
- Work through the program step by step to find the error.
- Try the first step, did it work?
- Then the second, how about now?
Remarks
If you make sure that everything is working line by line, then when you get to the place that your code isn't doing what it's supposed to, you know that you've found a bug. Once you've discovered your bug, you can work to fix (or "debug") it!
If you think it will build excitement in the class you can introduce the character of today's puzzles, Scrat from "Ice Age". If students aren't familiar with Scrat, show some video clips of the quirky squirrel running into trouble.
Main Activity (30 minutes)
Debugging in Maze
Before letting the students start on the computer, remind them of the advantages of pair programming and asking their peers for help. Sit students in pairs and recommend they ask at least two peers for help before they come to a teacher.
Display: Show “Debugging with the Step Button” video
Display: Show “Level 2-7 - Skill Building” slide
Display: Show “Level 9 - Predict” slide
Display: Show “Lesson Extras” slide
As mentioned in the purpose of this lesson, make sure the students are aware that they will face frustrating puzzles. Tell them it is okay to feel frustrated, but it is important to work through the problem and ask for help. As the students work through the puzzles, walk around to make sure no student is feeling so stuck that they aren't willing to continue anymore.
Wrap Up (5 minutes)
Reflection
**Display: Show “Reflect” slide
Reflect: Draw a bug you found in one of the puzzles today. What did you do to "debug" the program?
Extended Learning
Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.
Planting bugs
Have students go back through previous levels, purposefully adding bugs to their solutions. They can then ask other students to debug their work. This can also be done with paper puzzles.
When other students are debugging, make sure that the criticisms are constructive. If this could be a problem for your class, go over respectful debugging before this activity by role playing with another student.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.