Two large parts of an educator's role are to identify problems and to teach students skills to identify problems on their own. Debugging is a big part of any programmer's role as well. The debugging process can be particularly challenging and time-consuming for teachers. In this blog, we’ll explore some suggestions on how to find bugs in a quick and efficient way and how to help your students debug on their own too.
But before we get started, did you know that the phrase “debugging code” came from when real insects would get stuck in computers, causing them to crash? Computer scientists would discover an actual bug in the computer, remove it, and eventually, this process was called “debugging.”
The term “debugging” is now used to find errors that break code. So while actual bugs are no longer the root cause of code breaking, minor errors such as typos, misplaced characters, and more can cause a long string of code to break.
Here are 5 helpful tips on how to debug your students' code.
Click here to download a printable infographic that you can use in your classroom.
01 Learn how to read error messages
In many code environments, if your code is invalid or has a bug, it will spout out an error message. Kind of like when you go to a webpage and a large “404” appears instead of the site. This 404 number means that the webpage you’re requesting does not exist.
By learning what these different error messages mean in your code environment you will be able to get to the bottom of your bug much more quickly.
Here are three different kinds of bugs or errors you might see:
- Syntax error: this means that the characters were typed incorrectly (for example, a missing semicolon or misusing the assignment operator (=)).
- Semantic error: this means a word or variable was used in the wrong place
- Logic error: this means the code is technically written without mistakes, but the logic doesn’t accomplish the goal. For example, the code is running just fine, but it's not passing the challenge. This is because the code is correct, but isn't accomplishing what the directions required.
Now, these errors don’t necessarily mean that you have the answer to your problem right away. However, it will help narrow your search. If you’re unsure of what the error means, try searching for it on Google. The development world is very active on the internet. If you don’t know what an error message means, it’s highly likely someone else on the internet will.
02 Google it
This brings us to tip #2: Google it. As mentioned previously, developers are highly active on the internet and thrive on helping each other find solutions to their broken code.
When typing something into the Google search bar, be as detailed as possible. For example, make sure to include the type of technology you’re using as sometimes a device or the browser you’re using might have an effect on what is broken in your code.
Learning how to utilize Google as a computer science teacher and as a student is an essential skill.
03 Use the Rubber Duck Method
The Rubber Duck Method is a common debugging technique used by many developers. The idea is you have a rubber duck and you explain to this rubber duck, line by line, your code and what you’re wanting it to do. By talking through your code line by line you might notice mistakes that you miss when looking at it as a whole.
You do not need a rubber duck in order to practice this method. In fact, it’s probably best to have your student explain to you, aka the rubber duck, line by line their code and what they are hoping it does. Using this approach will most likely lead your student to the bug all on their own.
04 Take a break and think about something else
If you’re still having an issue finding the bug in your code, or your student’s code, it might be a good idea to take a break and work on something else. It’s important to make sure that you’re taking care of your mind while coding. It can be frustrating to spend lots of time searching for a bug.
There are a lot of fun games and challenges in Skill Struck that your student can try during this break. These games and challenges may even help them find their bug!
05 Use the Answer Keys (Teachers only 😉)
As a Skill Struck user, you can access answer keys for any challenge or activity within Skill Struck. As a teacher, searching the answer key may give you the answer you’re looking for, without the hassle of using Google or other search methods.
Bugs are common in code! Part of what makes coding so incredible is that it teaches students how to problem-solve. So while it may be frustrating when there is a bug in their code, you can use it as an opportunity for them to use the tips and tricks mentioned in this blog to work through the issue. Cheers to speedy problem-solving and happy coding!
To learn more about Skill Struck visit us at skillstruck.com