The Artima Developer Community
Sponsored Link

Weblogs Forum
Debuggers are a wasteful Timesink

90 replies on 7 pages. Most recent reply: Jun 1, 2005 1:53 AM by Brian Slesinsky

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 90 replies on 7 pages [ « | 1 2 3 4 5 6 7 | » ]
Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 12:57 PM
Reply to this message Reply
Advertisement
> Wow. Is it April Fool's Day already, because I assume
> you're kidding. Debuggers are an enormously important tool
> for real, commercial software development.

So many people believe. And yet I have not used one in years. IMHO there are too many folks who (by analogy) are trying to use electron microscopes when magnifying glasses will do.

Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 1:13 PM
Reply to this message Reply
A book is in progress for working with legacy code -- code that doesn't have working unit tests. A mailing list about it is here:

http://groups.yahoo.com/group/welc/

In the case of the incorrect file format bug - if the original programmer didn't write a test for a file in the wrong format, the maintenance programmer could add a test for that situation - documenting in a executable pass/fail way that the function would fail if the file was in a wrong format.

Thereafter, if the maintenance programmers kept the suite of unit tests passing, that piece of executable documentation would stay valid and useful for detecting unintentional side-effects of changes being made in the code.

Susan Jolly

Posts: 6
Nickname: brllady
Registered: Nov, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 1:27 PM
Reply to this message Reply
You are referring to only a small part of reality.

Where I come from, the person skilled with a debugger is the most valuable person on the team. Old mission-critical software cannot be understood by inspection. In many cases, this is related to the complexity of the algorithms and not (simply) poor software engineering practice. Think weather forecasting, climate modeling, oceanography, civil engineering apps. What you guys are talking about is trivial compared to what real programmers do.

I was once in situation where our company was phasing in the conversion of its mainframes from one in-house OS to another. There was just one last machine running the old OS for one more week when someone discovered that a long-used and stable program didn't function under the new OS. The developers were long gone. By running the program--otherwise unfamiliar to me--under the debuggers on the old-OS machine and on one of the new-OS ones, I found the problem had to do with an assumption about what a library function returned when the argument was at the limit of its range. (Can't remember the details, perhaps it had to do with the sign.)

Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 1:33 PM
Reply to this message Reply
> Only a couple of days back, I was diagnosing a bug: "Error
> while reading AFM file in PDF generator." Now, I have no
> clue what an AFM file is. I figured out it's an ascii file
> containing some font kerning information for PDF
> documents. Next, I don't know how the code works. I grep
> for the "AFM" and "read" in the code, and find a function
> called "ReadAFMFile" somewhere. Since I don't know the
> file format, I get lost in all the for and
> while loops. Print statements galore, but it
> makes little sense. Finally, I do manage to figure out the
> reason by "guessing" that it's a UNIX vs. MS-DOS format
> issue with the ascii file. I strip off all the carriage
> returns in the file, and bingo, it works!
>
> So this turned out to be simple. What if it wasn't, and if
> I had to actually find out the file format and how the
> parsing works?!

Wouldn't it have been nice if the code had been written in a clean and expressive way so that it told you how it worked? Wouldn't it have been nice if the code had been instrumented with unit tests that helped you understand it? Don't you think it is our professional duty to write code that eliminates the need for others to have to use debuggers to understand it?

> I think debuggers are very, very essential
> tools. I'd really like to hear how a debugger has ever
> wasted your time. Honestly, just how?

Simple. By trying to breakpoint my way into the failing context. I've spent hours trying to get to just the right point in the execution thread. I've spent hours in the wrong place, convinced it was the right place. I've spent hours backtracking from a context, not quite sure exactly how I got there. Only to find that the bug was stupdily obvious and I could have easily found it simply by reading the code that I was breakpointing through.

Note, I am not saying that there is not a place for debuggers. I just think that they should be considered a tool of last resort.


>
> Check out this article on "code spelunking":
> http://www.acmqueue.com/modules.php?name=Content&pa=showpag
> &pid=67

Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 1:37 PM
Reply to this message Reply
> You are referring to only a small part of reality.
>
> Where I come from, the person skilled with a debugger is
> the most valuable person on the team. Old
> mission-critical software cannot be understood by
> inspection. In many cases, this is related to the
> complexity of the algorithms and not (simply) poor
> software engineering practice. Think weather forecasting,
> climate modeling, oceanography, civil engineering apps.
> What you guys are talking about is trivial compared to
> what real programmers do.

Susan, you have no idea what kind of software I do. Believe me, it is not trivial -- even in comparison to the kinds of complex algorithms you are talking about.

Yes, it may be that a skilled debugger is very valuable in your environment. However, that speaks more to the quality of the code being debugged than the general usefulness of debuggers.

Again, I am not suggesting that debuggers never be used. I am suggesting that they ought to be considered a tool of last resort.

Robert C. Martin

Posts: 111
Nickname: unclebob
Registered: Apr, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 1:48 PM
Reply to this message Reply
> My debugger is just a really clever print
> statement.

A little *too* clever sometimes. A print statement does not (usually) interrupt the flow of execution. A breakpoint does. The difference can be significant. Have you ever blown an hour or two debugging the right code in the wrong context because you didn't realize that the breakpoint would get hit more than once, and so you used the first hit instead of the 17th?


> Yes, programmers can get into the habit of
> depending on the debugger. This means that perhaps we
> should try to instill some discipline

Which is, of course, the real point of the article. IMHO we should consider the use of a debugger to be a failure of discipline. It should be the tool of last resort when all our other disciplines have failed us.

>-- I would
> certainly agree that inspection should be performed first

Good.

> -- but branding the them "wasteful Timesinks" is simply
> idiotic.

I am not an idiot, and I don't appreciate the disrespect.

> Advocating print statements is simply
> indefensible.

And yet, idiot that I am, I will defend it.

> Print statements simply do the job of the
> debugger less quickly and less effectively.

Not in my opinion.

Celia Redmore

Posts: 21
Nickname: redmore
Registered: Jun, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 3:32 PM
Reply to this message Reply
Amazing! I thought I was the only one out there who found debuggers pretty much a waste of time.

In the earliest stages of coding, the bugs may be typos and other obvious errors. But those sort of simple defects should be quickly and easily fixed by inspection or unit tests.

After that come the places where you didn’t think out the logic properly – didn’t consider every possible combination of events. Debuggers aren’t much use there. In fact, I would be afraid of using a tool that tended to concentrate on such fine granularity – in case I fixed the symptom rather than the cause.

Ultimately, I can’t be self-righteous about using debuggers or not. It seems to be a personal style. Whatever works for you. Nobody can (or should) argue with results.

Susan Jolly

Posts: 6
Nickname: brllady
Registered: Nov, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 5:08 PM
Reply to this message Reply
I'm not quite sure why this topic has degenerated into name-calling but my point is that there are some areas where a debugger is a useful tool because of the nature of the problem being solved and NOT because of the quality of the implementation. Moreover, these areas represent some of the more significant uses of computational science and I think the use of debuggers should be taught as a skill. I do agree that many people don't understand how to use debuggers properly.

Here is an attempt to characterize the application areas where my claim applies. The key characteristic is that an application requires modules large enough such that a single module requires a team of developers and it is likely that some developers on the team will move on while new ones move in. The idea I'm trying to get across here with the word "module" is that it is intrinsic to the problem being solved that you cannot divide the implementation into cleanly separated pieces such that each piece is small enough for a single individual to maintain.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 6:31 PM
Reply to this message Reply
> Wouldn't it have been nice if the code had been written in
> a clean and expressive way so that it told you how it
> worked?

Well yes it would, but that's just wishing in the wind, isn't it. In any case, bugged code doesn't tell you how it works. It tells you how it doesn't work. You can't always deduce intent from implementation, doubly so when the implementation is wrong.

Viktor Szathmary

Posts: 3
Nickname: phraktle
Registered: Mar, 2003

Re: Debuggers are a wasteful Timesink Posted: Nov 30, 2003 8:59 PM
Reply to this message Reply
Another thing that I consider really important about adding tracing to the code, rather stepping thru in a debugger, is that it's repeatable. Done properly, the code can always stay instrumented with tracing, even in deployment, so if someone reports issues, you can essentially replay what happend.

Also, debuggers are mostly useless in a multithreaded application, when it comes to watching threads interact.

Susan Jolly

Posts: 6
Nickname: brllady
Registered: Nov, 2003

Re: Debuggers are a wasteful Timesink Posted: Dec 1, 2003 12:42 AM
Reply to this message Reply
The point about multi-threaded is well-taken. I've not worked enough with multiprocessor apps to have an opinion on the usefulness of debuggers in that environment.

Debugging allows you to do scientific experiments when you don't know what you are looking for. You can't instrument without anticipating. Here's an example of a problem I once solved with a debugger.

The input processor utilized a standard system library that read the user's input as string data and then parsed it, converting items to integers and floating point numbers as appropriate. Unbeknownst to any of us, the conversion routine resulted in the internal representation of a floating point value represented with a trailing zero after the decimal point being slightly different (by one bit on a 64-bit machine) from the apparently same value represented without that trailing zero. This difference led a user to observe a discrepancy in the output.

Instrumenting and debugging are complementary tools and they both have their place.

DrPizza

Posts: 3
Nickname: drpizza
Registered: Nov, 2003

Re: Debuggers are a wasteful Timesink Posted: Dec 1, 2003 12:48 AM
Reply to this message Reply
> A little *too* clever sometimes. A print statement does
> not (usually) interrupt the flow of execution.
So says the person who's never seen a printf statement magically fix some broken code. This is not unheard of (it happens because printf has a return value which normally ends up fixing some broken value on the stack which has resulted from improper initialization).

> A
> breakpoint does. The difference can be significant. Have
> you ever blown an hour or two debugging the right code in
> the wrong context because you didn't realize that the
> breakpoint would get hit more than once, and so you used
> the first hit instead of the 17th?
Honestly? No, not ever.

> Which is, of course, the real point of the article.
It doesn't appear to have been perceived in that way.

> IMHO
> we should consider the use of a debugger to be a failure
> of discipline. It should be the tool of last resort when
> all our other disciplines have failed us.
That simply wastes time; I can set and hit a breakpoint faster than I can type the print statements to perform printf debugging, let alone recompile and hit the print statements.

> I am not an idiot, and I don't appreciate the disrespect.
Even those who are not idiots occasionally do the idiotic. If I had meant to say that you were an idiot then I would have explicitly written such.

> And yet, idiot that I am, I will defend it.
Your words, not mine.

> Not in my opinion.
Then I'll race you. You can type System.err.println(/* whatever's needed here */); or whatever precise mechanism you prefer for printf debugging, I'll type ctrl-b to get a new breakpoint, and we'll see who can do so quicker. I'd put money on it being me.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Debuggers are a wasteful Timesink Posted: Dec 1, 2003 1:24 AM
Reply to this message Reply
> I'm not quite sure why this topic has degenerated into
> name-calling...

Could you give an example where this topic has degenerated into name-calling? I can't find it.

Vince.

Tim Vernum

Posts: 58
Nickname: tpv
Registered: Dec, 2002

Re: Debuggers are a wasteful Timesink Posted: Dec 1, 2003 2:32 AM
Reply to this message Reply
Once upon a time I avoided debuggers because they offered very little value. Once upon a time I avoided IDEs because they offered very little value. I have since decided I was wrong (well, actually technology caught up with me while I wasn't watching)

I regularly have developers come up to me and say "I have a unit test that's failing and I can't work out why". My answer is "Use the debugger, work out what's wrong, and then write a more specific test that will catch that behaviour explicitly.".

It sounds like you'd suggest either printf debugging, or writing more and more tests until you happen to find the bug. My experience says that both of those are wasting my client's money. In every scenario I've seen printf debugging was less efficient than firing up a debugger. I never seem to be able to know which printfs to put in, so I either overload myself with information, or I have to run the test over and over, each time with slightly different output.

Debugging by writing tests offers no client value. We have a test that fails. We know there is a bug and we know that if it comes back later we'll catch it again. Finding the existence of bugs by writing tests is a good thing. Finding the cause of bugs by writing tests it too much like fumbling around in the dark.

Or the other case "All my tests work in the IDE, and in the Ant build, but when the code is in the container it breaks my web test". Debug it in the container. A number of times I've watched people try and guess what's happening for an hour, and then I show them how to debug in container, and they fix the bug in 15 minutes.

The debugger is a great tool.
It's not the only tool, it's not always the best tool, but it's not the devil you seem to imply it is.

Maurizio Turatti

Posts: 12
Nickname: mkj6
Registered: Jun, 2003

Re: Debuggers are a wasteful Timesink Posted: Dec 1, 2003 3:58 AM
Reply to this message Reply
When I was a C++ programmer I was addicted to debuggers, but in the last two years of quite only Java development I have found myself using a debugger only a couple of times. It was not a deliberate decision, it happens. Debuggers are useful for inspecting complicated algorithms, but if you split your code in well refactored methods and write good tests, then there is not much room left to debuggers. I think debuggers are very useful when you really don't understand the algorithm, and you are trying to figure out what's going on inside.

Flat View: This topic has 90 replies on 7 pages [ « | 1  2  3  4  5  6  7 | » ]
Topic: A Real-World Example of a C++ Contract Verification Class Previous Topic   Next Topic Topic: C++ Meta-Binders


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us