Lesson 1: Debugging: Unspotted Bugs
Overview
This lesson will guide students through the steps of debugging. Students will learn the mantra: "What happened? What was supposed to happen? What does that tell you?"
Purpose
Research shows that some students have less trouble debugging a program than writing one when they first learn to code. In this lesson, we introduce the idea of debugging in a real world sense.
The goal in this lesson is to teach students steps to spot a bug and to increase persistence by showing them that it's normal to find mistakes. In later lessons, students will debug actual programs on Code.org.
Agenda
Warm Up (12 min)
Marble Run Breakdown (10 - 20 min)
Wrap Up (10 - 20 min)
Extended Learning
View on Code Studio
Objectives
Students will be able to:
- Express that they have noticed when something goes differently than what is expected.
- Identify what the expected result was before an error occurs.
- Determine and describe the difference between what was expected and what actually happened in the event of an error.
Preparation
- Watch the Unspotted Bugs - Teacher Video.
- Review the Unspotted Bugs Story (Unspotted Bugs - Storybook).
- Pre-read Unspotted Bugs to identify appropriate questions for your classroom.
- Follow instructions in the Marble Run - Teacher Prep Guide to make a Marble Run (which will be arranged incorrectly at the start).
- Give a Think Spot Journal - Reflection Journal to each student.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the Teachers
- Unspotted Bugs - Teacher Video
- Marble Run - Teacher Prep Guide
For the Students
- Unspotted Bugs - Storybook
- First Computer Bug - Student Video
- Think Spot Journal - Reflection Journal
Vocabulary
- Bug - Part of a program that does not work correctly.
- Debugging - Finding and fixing problems in an algorithm or program.
- Persistence - Trying again and again, even when something is very hard.
Support
Report a Bug
Teaching Guide
Warm Up (12 min)
Goal: Help students understand the steps involved in debugging.
Unspotted Bugs
This story can be presented in several ways, including:
- Circled up story time
- Projected with document camera / smartboard
- Pair shared with students at their computers
Lesson Tip
Important ideas from the story:
- What happened?
- What was supposed to happen?
- What does that tell you?
- Did it work at the first step?
- Did it work at the second step?
- Where did it go wrong?
The story of Unspotted Bugs presents many of the ideas that students will need to understand the debugging process of coding. This warm-up is meant to tie a memorable story together with a concept that young kids often find to be difficult.
Read the book and discuss the techniques that JD used to discover and take care of bugs. Make sure those questions and tactics get repeated often enough that students can recall (if not recite) them without the story in hand.
Potential Questions for Storytime:
- Page 3: What do you notice in the picture? What’s wrong with the flower? (It’s upside down!) What’s wrong with the clock? (The hands aren’t in the center) Why do you think there is something wrong with these items?(Because there are bugs on them!)
- Page 7: What’s wrong with the picture? (The lamp is upside down) Why is that? (There’s a bug)
- Page 11: What’s wrong in this scene? (The car doesn’t have wheels!) Why? (Because there are bugs on it!)
- What did JD find when he went looking for the bug? What was wrong? What does this mean? (JD found an upside down tree. This is wrong because the tree trunk should be touching the ground! This means there is a bug on the tree!)
Vocabulary
This lesson has three new and important vocabulary words:
-
Bug - Say it with me - Buhh-g. Something that is going wrong. An error.
-
Debugging - Say it with me: Dee-bug-ing. To find and fix errors.
-
Persistence - Say it with me: Purr-siss-tense. Not giving up. Persistence works best when you try things many different ways, many different times.
Marble Run Breakdown (10 - 20 min)
Goal: Help students think critically about the difference between what is happening and what is expected.
Debug the Run
Lesson Tip
Say:
Great! You all are so good at this, maybe you can help me with my own problem!
See, I have this marble run that I made. It comes in two pieces. When I put the ball in here (input A) it’s supposed to come out here (output A). When I put the ball in here (input B) it’s supposed to come out here (output B). Now, when I slide them together, I should be able to put the ball in here (input A) and have it come out here (output B). But it doesn’t work, watch.
[Slide the pieces together with output B facing output A.]
Watch what happens. [Drop ball at input A and notice that it does not come out output B.]
- BUG!
What happened?
- The ball fell on the table.
What was supposed to happen?
- The ball was supposed to drop from A into B.
What does that tell you?
- You should turn B around so that the ball goes into the right place!
Now that students have been introduced to the idea of looking for problems, they can try to apply it to more places in the real world. This next activity gives them practice looking for bugs in Marble Runs (a project that they will be working with next week.)
Grab your sample marble run (built from our plans, or something similar.) Show the students how each piece works, then demonstrate putting them together (but put them together incorrectly, to prevent the ball from flowing properly from A to B.
The goal of this exercise is to help the students identify when something goes wrong, so if they don’t catch it the first time, run it again, and again. It can help to make exaggerated frustration faces when the ball doesn’t do what you would like it to do.
Let the students share hypotheses about what is going wrong, and how to fix it. Students should feel free to try things that you know will be incorrect. If students misidentify solutions, use the bug finding formula on their configurations. Repeat until you get a working run.
Encouragement is key here. If things don’t work right away, praise the class for being so persistent and choosing not to give up. If they start to get frustrated, encourage them to persist a bit longer, promising them that they will get it soon if they just hang in there.
Wrap Up (10 - 20 min)
Journaling
Goal: Students will start to understand the importance of the activity they just completed by reflecting on it verbally, then through drawing in their journals.
Lesson Tip
Say:
What do you think we learned in this lesson?
- Debugging
- How to solve a problem
- How to make a marble go
- How do you think that can help us in other places?
Clear your mind:
It can be distracting to a learner when they have unanswered questions or doubts. To end this lesson, we’ll give everyone the chance to get those out so that they can reflect on what they’ve been taught.
Encourage students to share their thoughts and questions either with the whole class or with an elbow partner.
Journal Prompts:
Once they’ve had time to ponder their own thoughts, get the students thinking about the purpose of the lesson that they just learned. Why did you do this activity? How will it help them later? Can they think of buggy things that they’ve seen in the real world?
Students should finish by drawing or writing in their journal. Possible topics include:
- How do you feel when something that you are working on acts buggy?
- How many times do you think you should try to fix a bug before you give up?
- What would you do if you notice that something is buggy, but you don't know how to fix it?
Extended Learning
Lesson Tip:
The signs of real-live bugs won’t be as dramatic as upside down trees, but it might be dead leaves, spots on flowers, or slime on the
sidewalk. Have the students brainstorm these before going outside to look for them.
Real Life Bug Hunting
Take your students outside. Do you see any signs of bugs? What are they? Now look closer... can you find the actual bug?
Standards Alignment
View full course alignment
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
- 1A-AP-11 - Decompose (break down) the steps needed to solve a problem into a precise sequence of instructions.