Mastering Python Debugging Techniques Part 1

Mr Stucknet
3 min readJul 5, 2024

--

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.”
– Edsger W. Dijkstra

In the life of a professional coder, debugging and troubleshooting take up a
significant amount of time. Even if you work on the most beautiful code base ever written by a human, there will still be bugs in it; that is guaranteed. We spend an awful lot of time reading other people’s code and, in our opinion, a good software developer is someone who keeps an eye out for potential bugs, even when they’re reading code that is not reported to be wrong or buggy.

Being able to debug code efficiently and quickly is a skill that every coder needs to keep improving. Like testing, debugging is a skill that is best learned through experience. There are guidelines you can follow, but there is no magic book that will teach you everything you need to know in order to become good at this.

We feel that on this particular subject, we have learned the most from our colleagues. It amazes us to observe someone very skilled attacking a problem. We enjoy seeing the steps they take, the things they verify to exclude possible causes, and the way they consider the suspects that eventually lead them to a solution.

Every colleague we work with can teach us something, or surprise us with a fantastic guess that turns out to be the right one. When that happens, don’t just remain in wonderment (or worse, in envy), but seize the moment and ask them how they got to that guess and why. The answer will allow you to see whether there is something you can study in-depth later on so that, maybe next time, you’ll be the one who will catch the bug.

Some bugs are very easy to spot. They come out of coarse mistakes and, once you see the effects of those mistakes, it’s easy to find a solution that fixes the problem. But there are other bugs that are much more subtle, much more slippery, and require true expertise and a great deal of creativity and out-of-the-box thinking to be dealt with.

The worst of all, at least for us, are the non-deterministic ones. These sometimes happen, and sometimes don’t. Some happen only in environment A but not in environment B, even though A and B are supposed to be exactly the same. Those bugs are the truly evil ones, and they can drive you crazy.

And of course, bugs don’t just happen in the sandbox, right? With your boss telling you, “Don’t worry! Take your time to fix this. Have lunch first!” Nope. They happen on a Friday at half-past five, when your brain is cooked and you just want to go home. It’s in those moments when everyone is getting upset in split seconds, when your boss is breathing down your neck, that you have to be able to keep calm. And we do mean it. That’s the most important skill to have if you want to be able to fight bugs effectively. If you allow your mind to get stressed, say goodbye to creative thinking,
to logical deduction, and to everything you need at that moment. So, take a deep breath, sit properly, and focus.

In this series , we will try to demonstrate some useful techniques that you can employ according to the severity of the bug, and a few suggestions that will hopefully boost your weapons against bugs and issues.
Specifically, we’re going to look at the following:
•Debugging techniques
•Troubleshooting guidelines
•Profiling

That’s it for today. See you tomorrow.

If you love my blogs please consider helping me here.

--

--