Tuesday, February 16, 2010

How useful is a debugger, really?

(Inspired by this and this and informed by Linus.)

From the get-go, there's been a Perl debugger and lots of people think that it's a "Good Thing"™. Me, I've never seen the point. Yeah, I've used it. I know how to set breakpoints and step into functions and all that. I've used perl -d, gdb, the VB debugger, and the debuggers in both Firefox and IE (version 5-8). And I hate them all.

Well, hate is a strong word. Frankly, I don't see the point. There has never been a programming problem I've faced where using the debugger helped me. At all. In any language. Ever.

In 2000, I was lucky to be mentored by Ted Vessenes when we were working at Motorola. Ted is one of the most phenomenal programmers I've ever met and I know a bunch of brilliant people. Just to give you an idea of how freaking awesome he is, this is the guy that played so much Unreal Tournament that he got pissed at the AI and built a new one. Not a perfect player, but a perfect human player. His AI ended up being so good that he had to mess up his algorithms so that other people knew they were playing an AI. He literally passed the UT3 Turing Test.

Ted once told me "the most powerful debugging tool is print." (He actually told me this a bunch of times.) Or, restated - "If you need anything more than the print statement to debug a problem, then you don't understand the problem enough to solve it."

That means you, Mr. debugger. If I have to reach for you, that means I don't have enough context, knowledge, or whatever else I might need to solve the problem. In fact, I use my desire for a debugger as a litmus test. Anytime I want a debugger, I know I'm too stupid to fix it.

(Frankly, this goes for IDEs, too. If I need anything but vim to manage my project, then my project isn't organized properly.)

3 comments:

  1. "There has never been a programming problem I've faced where using the debugger helped me. At all. In any language. Ever."

    I would say that for scripting you are right, I totally agree with you. But, for compiled code (C++ for example), using GDB may save a lot of compilation time, cause you don't neet to add prints and recompile all the time.

    ReplyDelete
  2. One debugger I like quite a bit is the OCaml debugger. It's killer feature -- reverse debugging. You can step backwards in time! Very fun.

    ReplyDelete
  3. "If you need anything more than the print statement to debug a problem, then you don't understand the problem enough to solve it."

    That's precisely when a debugger is precious : when you don't understand the problem ! Maybe there is a strange interaction between several modules that you didn't write yourself, and you just don't know in advance what to print and where to insert the print statements. In such situations, the ability to go step by step, inspecting or modifying the state of the program, is invaluable.

    For example just today I had to solve a very strange bug in our application (seemed to behave in a random way). The bug was due to a line recently added somewhere deep in the code, more or less like

    my $var = get_some_value() if $some_condition;

    Know that one ? When the condition is false, perl does NOT initialize $var to undef; $var keeps the value from the previous execution of the same sub, like a 'state' variable in 5.10!

    Somewhere deep in my mind I knew about that stuff, but I'm sure I would have needed several days of "print statements" through many modules before finding that bug. With the help of the debugger it took less than one hour.

    ReplyDelete