I’m Fahim, a software developer turned tech founder. This article is part of my series: The Developer’s Launchpad. I’ll share my top lessons, hacks, and best practices for learning how to code and launching a new career — things I wish I would’ve known earlier in my journey. If you’re starting out your own coding journey, this series is for you.
Bugs — they happen to the best of us.
A bug is any issue in your code that is causing unexpected or undesired results. Bugs are an inevitable part of coding. As a result, learning how to resolve bugs (i.e. debugging) is an essential skill for your long-term success.
In my experience, the best programmers are also the best at debugging. Learning to debug effectively will help you better understand coding concepts, get more familiar with your code, and — in the long run — will make you more efficient at work.
If you’re a complete beginner or an early-stage coder, I’ll be sharing some perspectives to help you hit the ground running and become more effective at debugging.
I’ll cover:
Let’s do a quick rundown on bugs first.
In programming lore, the first computer “bug” was supposedly caused by a moth stuck in a computer at Harvard University.
If you don’t like insects, you can at least find relief in the fact that most coding bugs don’t involve actual bugs. That said, debugging can be far more complicated than removing a misplaced insect.
Software development is a complex process that works with various interconnected lines of code. Even if you know a given codebase, you may still inadvertently make a change that negatively affects the entire system (just as trying a new ingredient in a trusted recipe can unexpectedly yield negative results). You may have a bug arise simply because it’s being run on a different hardware setup for which it hasn’t been made compatible. Better yet, even if you didn’t do anything yourself, your software can suffer from bugs that originate from their _external_dependencies, such as third-party libraries.
In any case, bugs are inevitable. Whether you like it or not, you’ll have to get comfortable with them.
Ideally, you should hopefully find that you even enjoy debugging. There is certainly a great reward that comes with finally finding the source of the issues plaguing your code. It can be a challenge, but if you’re curious, you’ll only come out the other side having a stronger understanding of your code (and stronger problem-solving skills).
There are various types of software bugs.
Many bugs fall into two categories: syntax errors and semantic errors.
Syntax errors have to do with mistakes in your code’s syntax, including spelling, punctuation, improper naming, or omitting definitions for variables. On the other hand, semantic errors have to do with meaning. Semantic errors don’t stop the program from running — rather, the program does not operate as intended.
That said, bugs can also be grouped into other categories (some of which overlap with syntax and semantic errors):
You won’t encounter many of these bugs until you deal with more complex software. However, it helps to acquaint yourself with the different types, so you can discern the type that you’re dealing with.
Sometimes bugs will arise as a result of your human flaws, and that is okay!
I’ve experienced this hundreds of times. At first I think the code is right, and I’m convinced the problem is the compiler or the language… then I eventually realize the problem was me.
We’re human and we make human errors, whether they’re syntax errors or forgetting some nuances about our given programming language.
Keep calm, and try to have a sense of humor about it. It’s all part of the process!
If you’re stuck on a bug and don’t know what’s gone wrong, it can be frustrating.
But it will happen… so here are some helpful strategies you can try:
Ask yourself these questions to understand your problem:
Be resourceful as you try to understand what’s gone wrong. Make sure that you’ve been correctly using any functions, methods, or features by referencing documentation and other resources.
Calmly walk yourself through the problem at hand and how you’ve approached it. As you explain aloud, you may discover assumptions you’ve made or details you’ve missed along the way. This strategy is effective for many developers, and is what we call “rubber duck debugging.” (Rubber ducks aren’t necessary, but they do add a playful touch.)
There are various tools that will help you debug, and you should use them when you can! You can use specialized debugging software or built-in language tools like Python’s pdb
module.
Many integrated development environments (IDEs) include debugging tools as well.
The coding community is very willing to share knowledge and give feedback, so don’t hesitate to ask for help from other developers. It can be as simple as posting your problem in an online forum (with the bonus of knowing your query could help other coders in a similar situation).
Sometimes, all it takes to solve what seems to be an insurmountable problem is to look at it with fresh eyes. If you’re stuck on a problem and don’t know how to move forward, sometimes the best thing to do is walk away. Just disconnect from the problem entirely. If it comes down to it, sleep on it.
Remember, debugging isn’t about speed. It requires patience, persistence, curiosity, and attention to detail.
Debugging is one of many problem-solving processes that are the foundation of software development.
The better you get at debugging, the better a coder you’ll be. Over time, I hope you even learn to enjoy the debugging process.
As a reminder, you can find everything you need to go from your first line of code to your first job with Educative’s Learn to Code resources — courses, Skill Paths, and projects specifically for beginners.
Free Resources