Tag Archives: debugging strategies

Teach Debugging to Beginners to Build Confidence

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.

teach debugging to beginners

Teach debugging to beginners.

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.

syntax and indent error boxes in Python

When a student lacks debugging strategies the Python error messages can be a source of frustration.

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.

Python error

The word highlighted is not the error. It is the missing bracket BEFORE shape.

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.

Python error messages can seem like gibberish to beginners.

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.

Techniques to Teach Debugging Strategies

When designing a Python programming unit, include lessons with techniques to teach debugging strategies. Debugging is the ability to find and fix errors in code. It is a vital skill for young programmers to master.

Don’t hope that students will discover these strategies on their own. Instead, guide them through proven methods.

Explicit Strategy Instruction and Debugging Strategies

STEM classes emphasize writing code to animate objects, create artwork, or build games. In the push to build a program, the ability to edit the code may not be a focus of instruction. In this learning environment, identifying mistakes and correcting them becomes an implicit process.

During programming lessons, students need to decipher the meaning of error codes independently. They must spontaneously determine how to solve the problem. The young programmer can be left feeling inadequate as they struggle to get their programs to run.

Frustration is an integral part of the learning process. It fosters persistence, which is an admirable quality in a programmer. However, for many beginners, the challenges can seem insurmountable and they give up – telling themselves, “I am not good at programming”.

There is a better way!

Explicitly teaching debugging strategies empowers learners. No longer will they feel defeat when an error message appears. Instead, they have techniques to competently debug the Python program. This builds confidence and promotes a positive attitude towards STEM.

4 Techniques to Teach Debugging Strategies

1. Break It, Repair It

There are many techniques to teach debugging strategies. One that is very effective is to intentionally break code, then run the program to notice the result. This type of STEM lesson takes very little instructional time, yet quickly improves debugging skills.

To start, provide students with a Python file. Using direct instruction, have them systematically delete parts of the code to generate common errors. When the program is run, the instant feedback forms a connection between bugs, error messages, and how to fix the problem.

Some suggestions for breaking the code include:

  • remove vital lines such as the import of a library to note how commands are no longer recognized
  • add or delete punctuation such as quotes, brackets, colons, and commas to explore their purpose
  • adjust the indent level of a block of instructions to see how it influences the program
  • alter symbols such as ==, !=, <, and > then study how they alter the output
  • misspell a command to highlight the importance of accuracy when typing code
  • turn an equal sign == into = to notice how the code no longer works

Using these techniques to teach debugging strategies will enhance your students’ programming skills. If you are looking for a ready-made Python lesson, TechnoTurtle has a Bug Zapper exercise. Students follow instructions to produce bugs and then repair the code. This activity is ideal for beginners in Grades 3-9.

break the code

Intentionally break the code. This provides instant feedback when the program runs forming a connection between bugs, error messages, and how to fix the problem.

2. Code and Correct

Another debugging lesson is one that guides students through the development of a program. Using direct instruction, the teacher outlines the goal of the programming task. Line by line, the teacher types the code that the students copy. After each line, students run the program to study the output. When a mistake occurs, the teacher highlights the issue and explains how to troubleshoot the code. Slowly, the program takes shape.

This technique best suits students that are familiar with syntax and name errors. Instead of focusing on typos, this lesson emphasizes the quality of the output. It studies the outcome and provides solutions on how to improve the code. The sample program should be short. It must have common pitfalls to resolve as a class.

TechnoTurtle, a Python programming project for beginners, has several lessons that are ideal for a Code and Correct lesson. For example, students follow steps to draw a robot. Throughout the learning process, problems are intentionally generated. This provides an opportunity for beginners to think about the code and how to improve the program’s design.

techniques to teach debugging strategies

  TechnoTurtle includes techniques to teach debugging strategies. Follow the guided instructions to fix the code.

3. Explore and Investigate

Invite exploration into your STEM lessons to promote a positive attitude towards debugging. Often troubleshooting a program’s output can be a source of frustration. However, in this activity it is fun. Encourage students to play with different values to notice how they change the outcome. Investigate by making a number higher or lower. Or, replace a string with another option.

Explore and Investigate is meaningful. Active discovery demonstrates why one value is better suited to the program than another. It transforms mistakes into happy surprises.

Sparking a life-long interest in STEM is one of the goals of programming lessons. In TechnoTurtle, there are many activities in which students modify the values within a program to achieve a unique outcome. This makes learning enjoyable, which hopefully promotes an on-going interest in programming.

explore and investigate

Invite exploration into your STEM lessons to promote a positive attitude towards debugging.

4. Pick the Correct Code

Another technique to improve debugging skills is to provide students with snippets. Rather than mindlessly copying code they are presented with two options. One snippet is correct, the other has a bug. By making choices, the young programmers write the program.

This type of programming lesson actively engages students. They must study the code and think about the choice they will make. If they are incorrect, the feedback is instant. They can then use the other option instead. This activity cultivates a learning environment where it is safe to make mistakes.

An example of a similar programming activity is Clean Up the Code in TechnoTurtle. Young programmers determine how to debug the code. The program they are editing should stamp turtles on the canvas. However, it has four errors. For each error, they are given two choices. This activity builds debugging skills.

safe to make mistakes

Cultivate a learning environment where it is safe to make mistakes.

Apply Multiple Techniques to Teach Debugging Strategies

When teaching your next programming unit, design lessons that explicitly teach debugging strategies. This will build competence in your students and support independent learning. As well, this instructional approach has the potential to transform how students feel about errors. Turn your STEM classroom into a safe place to make mistakes.

Python Debugging Strategies for Beginners

Explicitly teaching Python debugging strategies provides students with a toolkit of techniques. The same debugging strategy cannot be applied to every problem. Provide students with a multitude of strategies and explain when they are most effective. This will enable programmers to thoughtfully debug their programs using a toolkit full of techniques.

10 Python Debugging Strategies for Beginners

Do not wait until the end of a programming unit to teach Python debugging strategies. Instead, help students find and fix bugs. Below are 10 techniques that will build confidence and independence in your students. They are based on using IDLE Python to write code. Many of these strategies are included in the Python project TechnoTurtle for elementary and middle school students.

1. Look Before Highlighted Word to Find Syntax Errors

Syntax is the set of rules for how to order words and use symbols to write code. If a bracket, colon, or indentation is missing the IDLE Python program will show a Syntax Error box on the screen to identify the problem. It will also highlight a word to pinpoint the location.

Do not be fooled! The problem is not the highlighted word. Instead the mistake is BEFORE it. Look at the words just in front of the highlighting, or the line of code above to find the error.

Syntax errors are often typos. Missing commas, hashtags, or too many brackets are common. If that isn’t the issue, study the order of the words as they might be put together wrong.

Python debugging strategies

Explicitly teaching Python debugging strategies. A Syntax Error is often missing symbols such as a colon, comma, or hashtag. Tell young programmers to look before the highlighted word.

2. Indent a Block of Instructions the Same Number of Spaces

Instructions that loop or run when a condition is met, are grouped together by indenting the lines of code to form a block. For example:

# correct way to make a loop
if answer==”tiger”:
    print(“You are right.”)
    print(“You win!”)

# wrong way to make a loop
if answer==”tiger”:
print(“You are right.”)
print(“You win!”)

When the code is not written correctly, IDLE Python will show a Syntax Error that states, “expected an indented block”. When this happens, check to see if the first line ends with a colon. If it does, then verify that each instruction in the block indents the same number of spaces.

3. Skim and Scan the Error Message to Find Clues

IDLE Python will display an error message in the Python Shell. It is in red text. To a novice, it can seem like gibberish. The best thing to do, is to scan the text for familiar words. Look for the line number. This will tell you where the error happened. To quickly go there within the program, right click the line number and select Go to file/line.

Before you view the line of code, study the bottom of the error message for more clues. It may say NameError at the bottom. If it does notice if the word is spelled correctly. If it is then check to see if a library was not imported or a variable was not defined properly.

Python error messages

Scan the message for clues. Look for the line number. Go to the last line to see if a function is spelled wrong. If it is right, you may have forgotten to import a library.

4. Look at the Color Coding

IDLE Python applies a color theme to text. This makes types of Python words different colors. This can be helpful when trying to find mistakes. Here are some helpful Python debugging strategies for beginners:

  • Comments are red. If a comment is not red, it is likely missing a # at the beginning, such as #this is a comment.
  • Strings are green. If a string is not green, it is likely missing quotes around it. Or, if a bracket is green, it likely that the end quote is missing.
Python color coding

Use color coding as a clue to find and fix errors.

5. Apply Trial and Error

A proven Python debugging strategy is Trial and Error. Trial and Error is a method of testing different ideas until one is found that works the best. The programmer will run their program and then study the output. They will notice the things that are wrong or unexpected. This analysis allows them to come up with a better idea to try next.

Trial and Error is systematic. The programmer only tries one idea at a time. This way they can pinpoint what is most effective.

Trial and Error is best applied when a programmer is fine-tuning the output. Their code has no syntax or naming errors. Instead, the focus is on discovering the ideal value or sequence of instructions to achieve the goal.

6. Code One Line at a Time

This Python debugging strategy can be used while writing a program or after it is written. When programming, type a line of code at a time and then run the program to test it. This allows you to quickly identify if there are typing errors or an issue with the sequence of instructions. This makes mistakes easier to spot.

Once a program is written, if you cannot find the mistake, divide the code into parts. Copy a chunk at a time into a new program. Run it to see it that section is error free. If it is, add another chunk of code to the program. Continue until you find where things are broken. Now you can focus your attention on that area.

7. Compare Using a Similar Model

If you cannot figure out what is wrong with the code and everything seems right, another Python debugging strategy is to find a similar program. Study the code to notice how it is constructed. This can provide a clue as to why the code is not working properly.

8. Copy and Paste from a Working Program

If you cannot debug the code and you are getting desperate, refer back to your previous work. Use existing code that is error-free as a jumping-off point. Copy a snippet of code that does a similar task from an existing program and paste it into the current file. Adjust the values or text to suit your programming objectives.

9. Enlarge the Font Size to Make the Code Easier to Read

When you have been programming for a long time the text can blur together. To make the lines of code sharper you can increase the font size or change the typeface to something that is easier to read. Now typos might be easier to spot. To do this:

  1. From the IDLE Editor Window, select the Options menu.
  2. Select Configure IDLE
  3. Click the Fonts/Tabs.
  4. Pick a font face such as Arial.
  5. Near the bottom pick a size such as 14.
  6. Click OK.
  7. Click the X to close the window.
IDLE Python options

Increase the font size and change the font to make bugs easier to spot.

10. Ask a Peer for Help

If you cannot find the error ask a friend for help. Often a fresh set of eyes can easily spot the typo in a line of code that has been looked over a hundred times. If the problem is related to the output, explain what you want the code to do. Look at the code together. Describe what is going right, and pinpoint where things start to go wrong. Run the program and study the outcome. Work together to discover a solution.

Python Debugging Strategies Support Learning

Make time to teach Python debugging strategies. Understanding how to code should not be restricted to those with a natural ability. Instead, provide your students with a toolkit of techniques they can use to find and fix errors. This will develop a positive attitude towards programming, build confidence, and promote independence.

Reasons To Explicitly Teach Debugging Strategies in Python

Teach debugging strategies to beginners. This will enhance the learning experience. The instruction should be evident and apparent to the students. Instead of hoping that young programmers will discover techniques, guide them through proven methods to find and fix errors.

Teach Debugging Strategies

Teach debugging strategies to promote independence, build confidence, and spark a life-long interest in programming.

10 Reasons to Teach Debugging Strategies

There are many benefits to deliberately teaching debugging strategies at the start of a programming unit:

1. Improve Comprehension

Teaching debugging strategies to beginners allows them to make sense of the Python programming language. Similar to reading comprehension, explicit strategy instruction, gives student the skills they need understand text. They learn how to decode the meaning of the error messages and apply techniques to correct the code.

2. Promote Independence

Guiding students through exercises where they break and then repair the code, promotes independent practice. During the activity, young programmers receive instant feedback about what makes code work. This allows them to take control of their own learning.

3. Develop a Deeper Understanding of Code

Young kids are always asking “Why?” As they grow older, they may not ask the question aloud as often but they continue to wonder about their world. When they are taught debugging strategies they begin to form connections to why a line of code must be written in a particular way. They understand the purpose for quotes, brackets, indents, and hashtags. Ultimately, this makes them better programmers.

4. Build Confidence

Young programmers can quickly become discouraged when their programs do not run. In the IDLE Python environment mistakes are highlighted in red with boxes that tell you instantly there is an error. This information on the screen is helpful if a learner knows how to apply it to correct the problem. However, if the meaning of the errors are unknown then they look like gibberish. Instead of having students struggle and give up, teach them strategies they can use to find and fix errors. Each success will build confidence.

5. Encourage a Positive Attitude Towards Programming

One of the goals to teaching programming to elementary and middle school students is to spark an interest in STEM. To ignite a passion for coding, the experience should be fun. Glaring at an error message with no idea how to fix the problem is not enjoyable. In fact, if it goes on too long it can make a novice dislike programming. Teaching students about common errors is empowering. They can make their programs run and see the results of their efforts, which is a great feeling.

6. Establish a Toolkit of Programming Techniques

The same debugging strategy cannot be applied to every problem. For example, Trial and Error is a wonderful way to test ideas. However, it can be inefficient when the issue is a loop missing indented instructions. Provide students with a multitude of strategies and explain when they are most effective. This will enable programmers to thoughtfully debug their programs using a toolkit full of techniques.

7. Reshape How Mistakes How Perceived

Children often believe that mistakes are “bad”. They don’t want their work to be imperfect. Teaching debugging strategies allows students to rethink mistakes. They become teaching tools that promote learning. Also, they enforce that not everything is wrong in the program. Instead only one thing is not quite right. The debugging technique of Trial and Error is an excellent way to celebrate mistakes. Students can experiment with different values or move a line of code to discover how it changes the output. The process of testing an idea and then studying the outcome is one way to put a positive spin on errors.

8. Make Programming Accessible to Everyone

Teaching debugging strategies makes programming attainable for everyone in the class. Success is not limited to only those students who have a natural ability. Instead, beginners can make original creations because they understand how to improve their code.

9. Avoid Classroom Management Problems

It is challenging for a teacher to help a class full of students struggling with the errors in their programs. As frustration levels grow, learners can quickly become disengaged. This can result in behavioral issues as they express how they are feeling. By knowing some simple but effective debugging strategies, students build the skills and confidence they need to troubleshoot code independently.

10. Provide a Foundation for Future Learning

Teaching debugging strategies is a great way to promote a life-long interest in programming. By successfully building programs, young programmers will want to make even more. They will be able to transfer their skills to more complicated programming tasks. Getting over the obstacles to learning at the start of a coding unit invites the possibility that students will continue to code in the future.

Python Lessons for Beginners

TechnoTurtle has programming activities that use explicit strategy instruction to teach debugging strategies. Students are guided through editing Python scripts to find and fix common errors. This provides a foundation for creating their own unique programs.

To learn more about TechnoTurtle, visit TechnoKids.