Exit Full View

print vs an interactive debugger

I grew up with poor tools, and my preferred debugging tool was the humble println statement. And I still use it!

I've heard people say that this is a bad practice, but I disagree. YMMV.

If a bug is simple, then I don't need any debugging tools. Create some test cases, and fix the code that causes them to fail.

The trick bugs, are those that aren't easily replicated by a small test case. For example, we can replicate a real-world bug that occurs on the 20th call to a particular function.

It takes me a lot less time to spam the code with println statements than stepping through the debugger to the point of the problem. It drives me mad when I step a little bit too far, and the bug is now in the past. I've not seen a debugger that can rewind!

Multi-threaded application make interactive debuggers even harder to use.

I find it very easy to run the code (at full speed) till the bug manifests, and then analyse the results at my leisure. Output to a file, or copy/paste it from the console to a text editor, and use the editor's Find tool to locate the portion of the log pertaining to the bug.

Make sure you do a git diff after the bug is squashed, so that you don't leave any stray debugging code behind.