DEV Community

Discussion on: Debugging - you’re doing it wrong. 10 techniques to find a bug in your code

Collapse
 
simbo1905 profile image
Simon Massey • Edited

The argument that not using a debugging tool is better somehow reminds me of when I was startling out a friend in the office met someone who prided themselves at writing code that compiled and ran correct first time. This was C back in the 90s where your compiler would puke for an hour and your test cases would crash with memory errors without any output. It would take me 20 attempts to get anything none trivial to run before I could even start to check its inputs and outputs to begin to get the logic right. My friend had asked the craftsman how long it took him to write the code they were looking at. The answer was that he took about twice as long as our trial and error approach that involved having the tool (the compiler) give us fast feedback on where our intent had been mistranscribed into code. Yet the person was extremely proud that they wrote code the way they did.

I think the argument that not using a tool like a debugger is in some way more... I am struggling for an adjective... “effective” or “beneficial” seems a little strange to me. If you are having to fix bugs on a large codebase of a team you just joined the best technique is make the bug repeatable, fire up a debugger, and step through. Running a debugger accelerates finding and fixing and also learning the code. You read the code as you step through but are looking at what it does not what the code as written claims it does. I can think of no more effect technique. I could go without the tool and use only other techniques, or I can use the tool and other techniques, and be squashing bugs faster. The clue is in the name of the tool!

What about if its not a large strange code base? Write a unit test, bang out some code, set a breakpoint at the top, and step through the code rewriting and moving the breakpoint. I find this an effective way to get from “looks finished” to ready to ship. Maybe it doesn't work for everyone all the time but a debugger is is certainly a core tool that every dev should be able to run on their codebases.