News for hackers. Stuff that matters.
Re:Hey, Don't Dump. Debug by jrockway on Friday May 01, 2009 @02:04PM (#588860)
I have never been a fan of debuggers, at least not for debugging application code. It's too tedious. One wrong keystroke (step over instead step into) and you throw all your work away. It is much easer to write a test script that exercises the bug, and then run that until the bug is fixed. (print is a great way to get information out of your program while debugging.) The added benefit is that this can become a regression test after you fix the bug, so the bug never comes back. I doubt a debugger can do that.

I will admit that sometimes I play with things in the REPL for a while instead of writing a script. This is somewhat like the debugger, but at a higher level (functions instead of lines), and more interactive. You can fix your faulty function, then hit M-p and try invoking it again until it works.

Re:Hey, Don't Dump. Debug by DLWormwood on Friday May 01, 2009 @04:19PM (#589077)
> One wrong keystroke (step over instead step into) and you throw all your work away.

That's what breakpoints are for, set the breakpoint just before where you "step too far" and try again... I personally find the "printf" technique too limiting, because it's not always obvious which variable is the one that had an unexpected value, especially if your programming to a commercial OS's API. Also, inserting an IO function will sometimes cause a subtle change in state or code compilation that causes "Heisenbugs."

But then again, I got spoiled by the debuggers in older environments like THINK Pascal, with "Observe" and "Instant" windows. It's only recently that IDEs like Xcode and Visual Studio finally attained functionality like that... (FYI, automatic variable watching and the ability to run "immediate" code while stepping.)

My big gripe with using debuggers with modern code, however, is the notion of using accessor functions. It makes what looks like only one line of code involve multiple jumps to other places, making "Step Into" a much less useful command...

Re:Hey, Don't Dump. Debug by jrockway on Friday May 01, 2009 @04:37PM (#589104)
It makes what looks like only one line of code involve multiple jumps to other places, making "Step Into" a much less useful command...

Hence you have to decide to "Step Into" and potentially waste a lot of time, or "Step Over" and miss your bug. This annoys me.

Re:Hey, Don't Dump. Debug by wvl on Friday May 01, 2009 @05:03PM (#589150)
One thing the article didn't mention is that when using ruby-debug you can drop into an irb shell from debugging. Best of both worlds.