A.I. Tools

Bugs in Python? Pdb to the Rescue! | by Marcin Kozak | Sep, 2023

PYTHON PROGRAMMING

Is the Pdb debugger worth learning and using?

Marcin Kozak
Towards Data Science
Debugging helps you learn from your failures. Photo by Brett Jordan on Unsplash

Various tools can be used to debug Python code, from the simplest print() function, via static but more advanced icecream and its sibling ycecream, to the various interactive debuggers that IDEs offer. My choice, however, has always been the built-in pdb debugger, along with the built-in breakpoint() function.

Debugging lies in the heart of programming. You start debugging when you start learning programming, and you stop debugging when you’ve promised you’ve just written your very last line of code — and if you keep that very promise.

You could think that one way to decrease the time spent on debugging your code is to write good code. Let’s face it: More often than not, writing good code means… debugging a lot during development. Certainly, a good programmer will write better code and make fewer mistakes — but this does not mean he or she does not need to debug.

There is, however, one way to debug less: To debug less, write good unit tests.

To debug less, write good unit tests.

Whether or not you’re using test-driven development, write good tests. Writing good tests means writing a sufficient number of well-written tests. I don’t aim here to discuss testing, so I’ll leave you with this thought; I wrote more about testing here:

We can assume that all programmers need to debug their code. Some may say they don’t, but that’s not true. They do; they simply don’t use dedicated debugging tools, called debuggers. Instead, they run their code for particular input, then they check it, and then, seeing something is wrong, they change the code and repeat the process. So, despite not using debuggers, they do debug their code; they just have to spend more time doing that. Debuggers were created for a reason!


Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Translate »