You’ve spent ages writing a brilliant piece of code, are excited to start running it, press ‘start’ and… nooooo – your code does something completely different or maybe doesn’t even run at all! An important part of programming is testing your program and ‘debugging’. While to some the term debugging may mean removing spiders before you climb in the bath, in the world of coding, debugging is the process of spotting and eliminating potential and current faults in computer code that can cause the program to go astray.
What is a bug?
A computer bug is an error or flaw in a computer program that prevents it from working correctly. Bugs can arise from human mistakes and errors in a program’s code or design.
Bugs have a wide range of effects, with varying levels of inconvenience to the programmer. Some bugs have a subtle effect on the program, the code can still function and lie undetected for a long time. More serious bugs are a major interference and may cause the program to crash or freeze.
It has been said that while most software programs have bugs, well-written programs contain relatively few bugs, and the bugs they do contain typically do not interfere with the program’s performance.
Types of bugs:
There are more than 1 million species of real bugs; from flies to butterflies and beetles to bees. While there are different types of bugs in your garden, there are also different types of bugs in computing, for example:
Syntax bugs
A syntax bug is an error in the code which will stop the program from working. This error, caused by something the programmer has typed, is known as a syntax bug and can range from small spelling mistakes to a command that the computer doesn’t understand.
Logical bugs
A logical bus is an error that doesn’t prevent the program from working. However, even though the computer is able to carry out instructions, it doesn’t act as the programmer intended/expected.
Do you know the difference?
You’ve programmed Marty to walk around an obstacle on a route. You hit ‘start’ on the program and Marty walks forward BUT, instead of avoiding the obstacle, Marty walks straight into it! Does your code have a syntax bug or a logical bug?
Marty is moving, just not going where they should! So, as the code is still running but not in the way intended, we can say that your code has a logical bug.
Process of debugging:
You’ve detected a bug but don’t know where to start? Should you look at the entire program or should you look at the section of the program that isn’t working properly?
For shorter programs, both options would work. However, for longer, more complicated programs a good debugging strategy would be to look for the part of the program that isn’t working properly, saving you countless hours going through every individual line of code! When searching for an error, you should try to think logically about where the problem might have occurred. This is much more efficient.
To debug a program, you must start with recognising there is a problem, then isolate the source of the problem, and then fix it. When the bug is removed, then the program is good to go!
Steps involved in debugging:
Next Steps:
Want to learn more about debugging? Why not check out our debugging lessons: Debugging with Marty Blocks and Debugging in Python!
Other posts you may like
Unlocking Student Engagement with Gamified Learning
The gamification of learning is revolutionizing classrooms, transforming traditional teaching methods into dynamic and interactive experiences. By incorporating game elements, educators are finding new ways to boost student engagement and...
Building Emotional Intelligence Through Robotics
This summer I had lots of chances to use my translation skills. Having over 40 languages and accents made traveling through places like the Netherlands, Italy, Iceland and Japan so much fun!
What I Did This Summer – by Marty the Robot
This summer I had lots of chances to use my translation skills. Having over 40 languages and accents made traveling through places like the Netherlands, Italy, Iceland and Japan so much fun!
TRY MARTY
FOR FREE
Are you looking for new STEM resources for your classroom? Robotical are loaning Marty the Robot to schools for no-obligation, 2 week trials.