3 ms·
Step by step often looses me, and print forces to think about what and where to print so it also has its advantages. This is a very good point. I have taught b
by userbinator 4y ago
Step by step often looses me, and print forces to think about what and where to print so it also has its advantages.
This is a very good point. I have taught beginners before, and saw many of them would somehow open the debugger in their IDE, then start stepping through all their code absentmindedly, as if the mere act of doing so would somehow cause the bug to become apparent. By the time they see something wrong, they've already gone well past the point at which the first error was. I have called this phenomenon "debugger tunnel-vision". It seems like the debugger is more like a ritual to them, some sort of magic that will automatically find bugs quickly and easily, and they get immensely confused when that strategy obviously doesn't work.
I turn them towards using prints, and many times they find the bug even before the next run of the program, while considering where and what to print.
IMHO the "tool fetish" that some programmers have is actually counterproductive.
- oreally 4y agoTools help you be more productive. The keystroke reduction in using debuggers far supercedes print debugging. Imo you've blamed tool fetish when it's really inexperience that is the problem.
- throw827474737 4y agoYou didn't get the point. My juniors work around fallout in some detail instead of solving the root cause or higher level systemic issue by just a little bit of thinking. Sure, there is the right time for a tool, but tbh all of my bugs are usually much quicker solved by thinking, understanding, unit tests with maybe a print than trying to catch something with breakpoints and stepping. And for the other nasty situations (think about concurrency, multiprocess, embedded irq handling) they are not even able to help but only professional tracing is (print-debugging always sounds so amateurish). So > Tools help you be more productive. The keystroke reduction in using debuggers far supercedes print debugging Sometimes yes, but in general I have seen those tools get into the way. For some reason I rarely need them and juniors often get mislead and don't see the forest for the trees.
- d883kd8 4y agoKeystrokes are so very much not the bottleneck
- Agingcoder 4y agoI very much agree with this (and I tend to fall into the debugger tunnel vision trap!). I therefore start by reading the logs and code, and if this doesn't work (it often does with a little practice), I use print statements. I have found that reverse debuggers (rr, pernosco) fix the tunnel vision issue by forcing you to identify something wrong ('no, this shouldn't happen') and then letting you work your way up, constantly asking questions ('ok, where is the next thing that doesn't make sense') instead of passively hitting F8. Basically, debugging is an active process, which requires a proper strategy, and print, code reading, and reverse debuggers all force you to have/design a strategy. Regular forward debugging doesn't in many cases, especially when you are not familiar with the code or the usual strategies you apply don't work in your slightly devious particular case.