3 ms·
I've never understood print debugging, at least in a web dev/nodejs context. I don't begrudge people having their own approach to things, but almost universall
by adam_arthur 6y ago
I've never understood print debugging, at least in a web dev/nodejs context.
I don't begrudge people having their own approach to things, but almost universally when I see people use print debugging they seem to take quite a bit longer than just break pointing at the problem area.
If your code is in an unexpected state, it's much easier to hit a breakpoint, examine local values, and then backstep through the call stack to see what went wrong. I dare to say that in a single threaded context, it's almost objectively more effective.
Versus the alternative of using printlines, you basically need to map/model the state flow out in your head which is prone to error (limited capacity of human working memory).
Is it not easier to directly see the problem rather than doing mental math to make assumptions about the problem? I can't see a case for that being more effective.
Most of the time I see people print debugging it seems to be because they haven't used the debugger much... either they aren't comfortable with it, or didn't bother to set it up, or see the mental mapping approach as more "mathematical/logical"... or something. Takes you back to the school days of solving algorithms on paper :)
That being said for simple problems, I've used print debugging myself (again, usually because I'm too lazy to setup the full debugger). Or for multithreaded contexts etc, where thinking it through can actually be more effective than looking directly at the problem (multiple contexts)
- nottorp 6y ago> almost universally when I see people use print debugging they seem to take quite a bit longer than just break pointing at the problem area. Could it be... because they don't know where the problem area is yet? Which is what the original article and most comments in favor of print debugging say.
- adam_arthur 6y agoHow can they not know? If you see unexpected behavior in some subsystem, it should be easy to pinpoint. e.g. in a UI context, timeline shows wrong data. Start there and work backwards. I can only imagine it's hard to pinpoint if the code is not factored well.