News for hackers. Stuff that matters.
Re:The unreasonable effectiveness of print debugging by dragonwriter on Saturday April 24, 2021 @01:12PM (#26926526)
> And I've also cringed watching ninjas step through code slowly, reading everything, spending 20 mins catching something 2 print statements would have achieved.

The problem is that the two print statements will only catch the bug if they are the right two, based on a correct hypothesis of what the bug is. Which, with a debugger, won’t require stepping, but setting two breakpoints, doing a run-to-breakpoint, and inspecting values.

Stepping is required when you are exploring behavior because you don’t have an easily testable hypothesis about the source of the bug.

Re:The unreasonable effectiveness of print debugging by cratermoon on Saturday April 24, 2021 @03:43PM (#26927727)
But with print statements if the first place I put them doesn't work, I can start doing bisects and quickly find the right place to print.

As you note, debugger breakpoints aren't magically better than print statements when I'm investigating a hypothesis – I'm no more likely to put them the right place than I would have put print statements.

And then there's a class of problems that neither debugger nor print statements will help: many years ago a very junior co-worker was wondering why his C code was giving the wrong answer for some math. It took me pointing out that one of the numeric types he was using in his code was different from the rest (I think it was #defined elsewhere, in some library, as an integer type). When the compiler did the math it had to do some type coercing.

Re:The unreasonable effectiveness of print debugging by dragonwriter on Saturday April 24, 2021 @03:52PM (#26927785)
> And then there's a class of problems that neither debugger nor print statements will help: many years ago a very junior co-worker was wondering why his C code was giving the wrong answer for some math. It took me pointing out that one of the numeric types he was using in his code was different from the rest

A debugger and watches on the values of concern absolutely will help with that (so will properly placed print statements), so its a really bad example. (Of course, strong typing helps even more with that particular case.)

Re:The unreasonable effectiveness of print debugging by cratermoon on Saturday April 24, 2021 @05:51PM (#26928481)
No, my co-worker was so junior he didn't understand why that was happening. It took me a moment to glance at the types in the source and point out the problem, no debugger needed.
Re:The unreasonable effectiveness of print debugging by jacques_chester on Saturday April 24, 2021 @05:31PM (#26928394)
> But with print statements if the first place I put them doesn't work, I can start doing bisects and quickly find the right place to print.

Can't I also bisect with breakpoints?

Re:The unreasonable effectiveness of print debugging by cratermoon on Saturday April 24, 2021 @06:00PM (#26928532)
You can, but the comment was talking specifically about stepping through the code line-by-line.
Re:The unreasonable effectiveness of print debugging by iudqnolq on Sunday April 25, 2021 @01:00AM (#26930438)
I can bisect faster with breakpoints. Plus with a time traveling debugger like rr the the time is further reduced.