It is important to teach debugging to beginners right away. Debugging is when a programmer finds “bugs” or errors in their code and fixes them to improve the program. This is an essential programming skill. So much so, that it should be taught at the beginning of a coding unit.
Where Were the Debugging Strategies in the Instructional Materials and Python Courses?
When I was asked to develop Python materials for TechnoKids Inc. I jumped at the chance. I began to read books about Python. They had titles emphasizing that the instructions inside were for “absolute beginners”. I noticed that none had activities or advice on debugging. Instead, if the code I was copying from the page didn’t work I was left guessing why. It was frustrating!
My reaction was one that I knew students would feel. I worried that young programmers might begin to think “I am not good at programming” when they encountered an error they could not fix. This belief might turn them away from learning more about coding. I knew it was necessary to reframe how students respond to mistakes in their programs. They needed to feel empowered, not defeated.
The books were helpful in understanding the types of instructional materials available to teachers on teaching Python – but I needed to learn more!
I wanted to understand the difference between what young children and young adults were learning about Python. I signed up for a first year course at the university where I did my undergraduate degree. This course did have a section on debugging, but it was at the end of the course. I asked the professor why it was introduced so late and was told it was because beginners could not understand the error messages until they had learned how to code. As a result, I spent a good portion of the course inefficiently applying debugging strategies. I knew there had to be a better way!
When it came time to create the TechnoKids Python STEM projects I had reached a decision…debugging needed to be taught right away. I wanted students to be able to understand the meaning of the errors they would see. More importantly, I knew they needed simple strategies to fix their code.
What Happens When the Program Keeps Shouting ‘You Are Wrong’…But You Don’t Know How to Make it Right?
When Students Lack Debugging Strategies, Red X’s Tell the Learner They Can’t Code
During my investigation of Python programming with kids I noticed that there were common errors made. These mistakes would trigger several responses by the IDLE Python program. The Python Editor Window, which is where programmers build the code, will display a box with a red x on Windows devices. Those are for syntax or indent errors. In this case, there might be a forgotten bracket or # in front of a comment: simple to fix, but not without knowledge of debugging.
The angry red x’s that show up on the screen mock a novice. Unintentionally they seem to say “you can’t code”. To prevent students from becoming discouraged, teachers should provide strategies for decoding error messages. This will build confidence and promote independence.
When Students Lack Debugging Strategies, They Can’t Find the Problem
Another technique the IDLE Python program uses to assist programmers is to identify a spot within the code where there is an issue. This is accomplished with a reddish-pink box around text. The skilled programmer knows to look BEFORE the highlight.
However, those without debugging strategies can stare at the code forever and never know what is wrong. This is because children and young adults are literal. They look at the reddish-pink text and say “Oh, the problem is right HERE”. Beginners lack sufficient knowledge to locate the error. This shortcoming can easily be overcome by explicitly teaching debugging strategies.
When Students Lack Debugging Strategies, Red Text Tells a Beginner They Do Not Understand How to Program
The error response by the IDLE Python program is to show a message in the Python Shell. The text is red. It often tells the programmer there is a name or type error. These errors can occur if a library is not imported, a command is spelled wrong, a variable is not used properly in the code, or a sentence does not use the correct punctuation for joining text with variables. The Python message identifies the line number and reason for the problem. However, with no debugging strategies it can seem like gibberish.
The red text in the Python Shell is the equivalent of using a red pen to grade student work. Many educators have given up this practice as it promotes self-esteem issues, which can turn students away from wanting to learn. Studies have show that for many learners red pen is like ALL CAPS. It yells “You are wrong!” When red text is the method for highlighting errors, it can make a student feel angry or sad. This is avoidable when educators teach debugging to beginners at the start of a coding unit.
Teach Debugging to Beginners at the Start of a Coding Unit
To avoid making students feel bad about themselves, why not just give students perfect code to copy? Then when they run the program, no errors will happen. Or if they do, they can quickly refer to their sample to find the typo. Problem solved!
No. Not really.
The limitation to this instructional approach is that it restricts learning. One of the goals of teaching a STEM project should be to support students so they produce their own original creations. Aside from developing programming skills, the learning objectives in a programming unit should include: fostering an interest in programming, developing computational thinking skills, and applying logic and reasoning to solve a problem. The aim should not be improving typing skills.
Spark an ongoing interest in programming. Teach debugging strategies at the beginning of a coding unit. This will build confidence and promote independence.
Python Lessons that Explicitly Teach Debugging to Beginners
Teachers need to deliberately teach debugging strategies at the start of a programming unit. This empowers students. Using this instructional approach, the TechnoTurtle STEM project includes activities that teach students about common errors and how to fix the code.
TechnoTurtle has 30 coding assignments. Elementary and middle students solve mazes, create artwork, and build games. Several of the lessons emphasize debugging strategies. They are interwoven throughout the project to introduce or reinforce computer science concepts:
- Edit a Python Program: Modify values to understand the purpose of code.
- Bug Zapper: Add mistakes to a program to learn how to debug Python.
- Clean Up the Code: Fix coding errors by selecting from the list of choices.
- Trial and Error: Test different ideas to move a Turtle through a maze.
- Draw a Robot: Write one line of code at a time and make corrections as you go.
- Edit an Invitation: Change code to discover how to join text with variables.