Lesson 7: Debugging

App Lab

Overview

In this lesson students practice using the different programming concepts that they were introduced to in the last lesson. To begin, however, they are introduced to the concept of debugging and are encouraged to use and reflect on this practice throughout the lesson. At the end of the lesson students share their experiences debugging as well as an new realizations about programming.

Purpose

This lesson serves a number of roles. Even if students had modified programs in the previous lesson, this continues to be an introduction to many of the skills of programming. Students are also introduced to debugging as a skill they'll need to use and develop as programmers. A huge goal of this lesson, however, is attitudinal.

Agenda

Lesson Modifications

Warm Up (5 mins)

Activity (30 mins)

Wrap Up (10 mins)

View on Code Studio

Objectives

Students will be able to:

  • Debug simple sequential and event-driven programs
  • Use the debugging process and Identify specific best practices for debugging programs
  • Use the speed slider, break points, and documentation as part of the debugging process

Preparation

  • Review the steps of the debugging process
  • Review the levels students will need to complete on Code Studio

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teachers

Teaching Guide

Lesson Modifications

Attention, teachers! If you are teaching virtually or in a socially-distanced classroom, please read the full lesson plan below, then click here to access the modifications.

Warm Up (5 mins)

Preview the Lesson

Discussion Goal

Optional Warmup Prompt: This prompt is optional and included for instances where you need a warm up prompt on the board when students walk in. If your classroom is able to move directly to main activity you should feel free to skip this prompt in the interest of time.

Goal: This prompt should help get students in the mindset of debugging. If students ask for more details tell them that this is all the information they have and that they should feel free to

Prompt: Your friend calls and says "I can't get music to come out of my speakers, can you help?". Write a quick list of everything you'd ask them or have them check to try to fix the problem.

Remarks

Today we're going to practice programming, but we're also going to practice a very important skill in programming called "debugging". Let's see what it looks like.

Activity (30 mins)

Practice Time

Display: Show the Debugging video and then show the debugging process.

Remarks

We're going to use this process to help us fix programs. I want you to use this process as you fix issues you find in code today. At the end of the lesson we'll talk more about this process and any specific strategies you document along the way.

Group: Place students in pairs.

Level 2: This level requires students to recognize that strings need to go in quotes.

Level 3: This level also requires students to recognize that strings need to go in quotes. Ideally students will get more familiar with checking for yellow warnings in this level.

Level 4: The code in this level will run, but the wrong text and sounds have been placed in the wrong places. This shows that code may have no warnings but still is not working correctly.

Level 5: Again this code has no warnings but in testing the app students should see that the range of values for the random numbers is too large. Iterative testing with different values should help them pick a number that keeps the smiley inside the screen.

Level 6: In this level an entire event handler is missing. Students will need to add it to the app.

Level 7: This level explicitly introduces the fact that event handlers (onEvent) should not go inside other onEvent blocks. This is explicitly addressed in the concluding slide show as well.

Level 8: This app is a good chance for students to practice adding functionality of their own. While nothing starts off as "broken", students will need to use debugging practices as they add code to this app.

Wrap Up (10 mins)

Discussion Goal

Goal: This discussion should help reinforce the fact that debugging is a skill that can be learned and that it is made up of many little steps and understandings. Give the room an opportunity to share as many ideas as they can before sharing the provided slides with some recommended steps.

Prompt: If you were using the debugging process then you should have some notes of good debugging tips. Share those with your neighbor and add any new ones you forgot to add. Be ready to share with the class.

Display: Show the slide which lists some best practices in addition to those students may have mentioned.

Remarks

Debugging is an important and entirely normal part of programming. Your code won't always work the first time, and that's OK! Debugging is a skill that you can practice and get better at. Using documentation and leaving comments for yourself are important skills, but so is working with classmates or learning to more effectively search for bugs. We'll keep using these skills.

Journal: Have students add the following vocabulary words and definitions to their journals: documentation and comment.

Remarks

Let's take a minute to talk more about comments and documentation. Comments help explain the code, but do not affect how the program runs. They are meant to be read by people! When we write code, we don't only write for the computer we also write for other people. It's important that others can understand our code, so write your code clearly using the practices we discussed and comments.

Not all programming environments support comments, so other forms of documentation may be important like keeping a separate document with information about your program. The key takeaway here, is no matter what the format, comments and documentation are important!

As you grow in your programming skills, you will start to appreciate how valuable comments can be. You don't have to wait until a program is complete to write the comments. You should be doing this as you develop the project. There will be opportunities to write comments called out in the App project you are currently working on.


Assessment: Check For Understanding

Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.

  • What is one thing you really enjoyed about today's activity?
  • Is there anything that you found confusing or need extra help with?

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

CS - Computing Systems
  • 3A-CS-03 - Develop guidelines that convey systematic troubleshooting strategies that others can use to identify and fix errors.

CSP2021

AAP-2 - The way statements are sequenced and combined in a program determines the computed result
AAP-2.B - Represent a step-by-step algorithmic process using sequential code statements.
  • AAP-2.B.7 - Clarity and readability are important considerations when expressing an algorithm in a programming language.
CRD-2 - Developers create and innovate using an iterative design process
CRD-2.G - Describe the purpose of a code segment or program by writing documentation.
  • CRD-2.G.1 - Program documentation is a written description of the function of a code segment, event, procedure, or program and how it was developed.
  • CRD-2.G.2 - Comments are a form of program documentation written into the program to be read by people and do not affect how a program runs.
  • CRD-2.G.3 - Programmers should document a program throughout its development.
  • CRD-2.G.4 - Program documentation helps in developing and maintaining correct programs when working individually or in collaborative programming environments.
  • CRD-2.G.5 - Not all programming environments support comments, so other methods of documentation may be required.
CRD-2.I - For errors in an algorithm or program: a. Identify the error. b. Correct the error.
  • CRD-2.I.5 - The following are effective ways to find and correct errors: ●        test cases ●        hand tracing ●        visualizations ●        debuggers ●        adding extra output statement(s)