10 best practices for helping students debug their code

Kelly Lougheed
upperlinecode
Published in
7 min readJul 17, 2019

Software developers estimate spending up to 50% of their time debugging code. It’s safe to say that computer science classes also see their fair share of debugging! Here are a few best practices for computer science teachers to help students not only debug their code, but also develop problem-solving skills and confidence.

1. Anticipate common mistakes.

Cut down on bugs in the first place by preempting common student errors. As you go through a codealong, literally warn students of potential pitfalls: “A common mistake students make is to just start using a variable without declaring it. But before you can use x, first you have to say int x…”

Tailor your teaching to address common student errors. For instance, knowing that many students struggle with proper indentation in Python, you might choose to make a big deal out of this as you teach Python control structures.

Knowledge about common errors usually comes from experience teaching particular programming languages and computer science in general. But if you’re a newbie, don’t despair!

Stay up to date on computing education research by reading bloggers like Mark Guzdial and following CS educators on Twitter — not just K-12 teachers, but also CS professors who research pedagogy. Explore academic papers that analyze common CS student errors and misconceptions. If you’re about to teach a particular topic, hop into one of the CS teachers Facebook groups (APCSA, APCSP, CS Educators) and ask for tips, or use the search function see what’s been discussed before.

2. Make thinking visible.

When you sit down to help students work through their bugs, illuminate misconceptions they might have about programming by asking them about certain parts of their code: “Walk me through this function” or “What is this line supposed to do?”

Sometimes students will confess that they have no idea. From there, you can ask them what they would like their code to do, and prompt them to brainstorm solutions.

Other times, when students explain their code, their (possibly mistaken) thinking becomes visible. For instance, maybe they think variables can store multiple values, instead of having the new value overwrite the old one.

You can address the misconception, the root cause of their bug. Once you clear up their misunderstanding, they will be much better equipped to continue programming and less likely to create similar bugs.

3. Ask leading questions.

Instead of telling students how to solve their bug, help them develop their reasoning skills by asking them leading questions that direct them to a possible solution.

  • “Do we know of any control structures that can repeat lines of code?”
  • “Is there a way to pass that local variable into the function?”
  • “Lines 20 and 21 look good, but something’s missing on line 22. What do the first two lines have that line 22 doesn’t have?”

Leading questions empower students by having them come up with the solution themselves.

4. Normalize errors.

Create a classroom culture where errors are totally normal. Every time you compile your code in front of the class, announce that you’re going to check for any errors, which are just a normal part of a programmer’s life. Whenever you get an error or when a student sheepishly confesses that they have 20 compiler errors, remark on how totally normal that is.

Go the extra step and get excited when a student says they have 20 errors, or even better, a “fatal error”! Model being unfazed by errors and in fact seeing errors as an opportunity to learn new things. As a teacher, helping students debug IS an opportunity for you to learn more about how to be a better teacher and anticipate a wider range of student errors!

When you model this attitude, students will follow suit. As a result, they will be less likely to get discouraged by 20 compiler errors and may even find humor in it.

5. Establish a Personal Empowerment Protocol.

When a student asks for help and you see they’ve made an elementary mistake, it’s tempting to immediately swoop in and start helping them. Unfortunately, this instant assistance makes the student more dependent on the teacher to solve their bugs. Instead of reading their error messages and attempting to solve the bug on their own, students will simply raise their hand and wait for help.

Establish procedures that help students solve their own bugs. Protocols such as the “Personal Empowerment Protocol” or “Ask Three, Then Me” encourage students to use their resources. Generally, when they encounter a bug, students should 1) ask their partner, 2) ask another pair, and 3) Google it before they finally ask the teacher.

Introduce the Personal Empowerment Protocol at the beginning of the year or any natural time to start afresh (like a Monday). Frame it as an opportunity for students to develop independence and problem-solving abilities. Post a copy of it on the classroom wall to remind students of this routine.

6. Enforce the Personal Empowerment Protocol.

To help students actually follow the protocol, check how thoroughly they’ve followed it when you ask for assistance. Ask a few questions before you offer help:

  • “What’s going wrong?”
  • “What’s the error message?”
  • “What have you tried so far?”

If students haven’t tried anything so far, encourage them to consult classmates and Google it, and you’ll be back. (This is your cue to start walking away so they can work independently.) If they’ve made a fair attempt to solve their bug but still need assistance, you can step in to help.

7. Squash every bug.

It’s great to empower students by giving them space to debug their own code, but you also don’t want them to feel abandoned. Even though learning through inquiry allows students to develop problem-solving and reasoning skills, students still want to feel that their teacher is helping and supporting them.

When students say that they have followed the Personal Empowerment Protocol and they still can’t find the solution, step in with the strategies above and guide them through squashing their bug.

If you don’t immediately see the origin of the bug, it’s completely acceptable to have them Slack or email you their code, and for you to spend some time poking at it on your own machine. This might take place during class (if no one else needs help) or after class, and you can send a follow-up email when you find their error. Students will appreciate that you took the extra time to help them out.

If there’s a bug you can’t solve, turn to the computer science communities on Facebook and Twitter! Another teacher will likely be able to help you.

8. Take a break.

If students have been wrestling with a bug for a while, encourage them to take a brain break! They can stand up and stretch, have a dance break, or do a lap around the classroom, perhaps checking in on their classmates’ programs and offering help to anyone who needs it.

After taking some time away from the buggy code, it can be easier to see silly typos and syntax errors, as well as flaws in logical thinking.

Students often don’t want to tear themselves away from their computers and can get obsessed with debugging tricky code, so preach the benefits of taking breaks! Especially if students are consumed in projects, encourage them — and even require them — to take brain breaks.

9. Lower the student-teacher ratio through strategic moves.

The student-teacher ratio is rarely in the teacher’s control, but a low ratio helps give students personal attention (once they’ve followed the Personal Empowerment Protocol, of course!). You probably can’t clone yourself, but there are some clever ways to simulate a lower student-teacher ratio when you need it.

If you have a large class, and you anticipate that your students will need a lot of help during a particular class period (e.g. as they’re working on a final project), it may be worth checking in with a colleague to see if they can help you out as an extra troubleshooter during that period (obviously, offer some food, lunch duty coverage, eternal gratitude, etc. in return).

If you have older students who need community service hours or are potentially interested in a career in education, look into a situation where they could serve as TA.

For beginners, programming can be a frustrating endeavor, and errors can be real roadblocks. One-on-one support and guidance can help build student confidence.

10. Teach and practice debugging.

Debugging is an essential skill in programming, yet it is not always explicitly taught!

Teach students first how to read errors. During codealongs, purposely generate errors and point out how the computer helpfully gives the programmer a clue about what the error is, and also the line number causing it. Point out that errors may be either on that line, or they may be caused by a line about it. Model Googling an error message for help.

Show students the power of print statements for tracking what your code is doing and what value a given variable holds. Later, more experienced students can graduate to using the debugger on their IDE.

Many pre-made CS curricula offer debugging activities to help students develop debugging skills as well. For example, the Debug It! activities in the Scratch Curriculum Guide provide buggy programs that students need to fix. Students can journal about errors they found and how they solved them.

You can also have your students generate debugging activities. Each student writes a buggy program (or throws a bug into an example program that you provide) and adds their code or program URL into a shared Google doc. Encourage students to make #relatable errors that they themselves have made.

Then everyone makes a copy of the Google doc and debugs each other’s programs! In the Google doc, students should provide the corrected code and an explanation of their fix.

Debugging exercises help students practice both problem-solving and reading code, a known area of difficulty. It also helps normalize debugging as part of a programmer’s daily life!

Conclusion

Helping students debug is walking a fine line between giving them the space to develop problem-solving skills and giving them the support to develop their confidence. Use these strategies as they make sense for your class’s particular needs.

--

--