February 07, 2007More testing doesn't mean less debuggingThis myth that "testing means no more debugging" needs to die. Seriously. Anyone making this claim is doing a lot of damage to the software engineering world. Just as we are finally getting good IDE's, good debuggers and, more importantly, an increasingly widespread conviction in the developer community that these tools are part of a healthy software engineering process, a new vanguard of smug programmers come out of the woodwork with their superior attitude and resurrect the old mantra that only bad developers use debuggers. Enough already. Yes, testing is important, and promoting testing is laudable, but not at the expense of equally useful tools and practices that it took us decades to hone and perfect. Ever since I've become serious at testing, my usage of debuggers has increased, if only because I write more code now than before (I didn't used to write any tests), and this extra code needs to be debugged, like any other. Or do these people assume that just because the code that you write is called "tests", it's suddenly become bug-free? But here is my real secret: most of the time, I don't use a debugger to debug. I use it to verify that my code works as I think it does. That's right: I launch my debugger even before a bug has manifested itself. Even before my code is working at all! I launch it to inspect all the variables, verify my assumptions, stare at my code for what it really is, not for what my biased view tells me it is. I also use the debugger to modify variables and try to trip my code, cause errors that could or shouldn't happen and make sure it reacts accordingly. Of course, eventually, I capture all of this in tests, but these approaches are complementary. Don't throw away your debugger, or the quality of your code will suffer. Posted by cedric at February 7, 2007 10:15 AM Comments
Hi Cédric, I can't help wondering what sort of a crusade you're starting - and also what peculiar (from my perspective) habit you have in your usage of the debugger ;-) My humble opinion: there is no more evidence (at least neither you nor your "opponents" give any sort of scientific proof) that more testing means less debugging than the contrary. I certainly have an opinion - I see how I worked in the past/work now - but I'm aware it's only an opinion. Stop using the old argument of authority - prove what you claim or be humble enough to state that you have respectively haven't noticed this or that evolution in your style. And I definitely don't see how having a different opinion about this matter "is doing a lot of damage to the software engineering world". Have you heard about someone being fired/threatened/killed because s/he used a debugger? And even if so: this wouldn't prove that this opinion is damaging but that there are pretty dangerous jerks in the software engineering world. Concerning your habit to start debugging "to verify that [your] code works as [you] think it does.": that's one of the most astonishing things I heard/read for years. I could be very sarcastic about that - but as it would lead nowhere I prefer to say that I use test precisely for that and resort to the debugger if things don't behave as I expect and I have to admit to myself that I'm too dumb to find the core cause of my program's behavior through testing and review/analysis of the code... When I finally find what the cause of the problem was, I try to write a test (not always: [here an endless list of good and bad excuses...]) that nails it before I correct the error - but more often than not I rewrite the program so that it's simpler to read/understand so that such an error cannot occur anymore... As far as the debugger is concerned: I see it as a tool among others in my IDE. I would certainly not want to miss it, but I'd rather give up the debugger than my habit of writing tests. As no one forces me to make such a silly choice, I'll continue to use debugger/tests the way I think it leads me to my goal (software that does what I intend it to do...) Erik PS I would really appreciate if developers could stop behaving and talking like religious fanatics - there are enough of those everywhere :-( Posted by: ErikFK at February 7, 2007 11:13 AMI don't really know what to say about that. I agree that the myth "testing means no more debugging" needs to die. But from where I see it, it's already dead. I like to see testing as "less" debugging. Debugging things you don't need to debug is pointless. Also, I share with you the feeling that I've been using the debugger more often, probably because debugging a very small program such as a test is far easier that a whole application. Posted by: Tiago Silveira at February 7, 2007 01:44 PM> Also, I share with you the feeling that I've been That's an interesting observation. If my app is misbehaving, but my tests are passing (or I don'tr have any tests), then it's quite hard to sort out. I sit with the code, and I walk through it, and look at the logs, and try and see if I can work out where the problem might be. But if my test is failing, I have a quick look at the code to get my head around the problem and see whether I can understand why that problem might be there. After that I fire up the debugger. The test is (usually) a small enough problem space that I can use a debugger efficiently. Posted by: Tim Vernum at February 7, 2007 04:14 PMThat mentality is even more dangerous when it gets into toolkit / framework writers hands. Far too often these "book"/academic programmers focus only on the ideal and leave you twisting in the wind when you are faced with real problems that you they hadn't anticipated. I like to think that those edge cases are where we separate the wannabes from the programmers. Posted by: Jesse Kuhnert at February 7, 2007 07:52 PMI would put it this way: I don't think anybody says testing means no debugging. Anybody who gets an unexpectedly failing test or legacy code has to spend time debugging. However, I certainly spend a _lot_ less time debugging than I used to before I started TDD. The use of a debugger is an entirely different question. I certainly occasionally use it for exploratory testing, looking at other peoples code. However my use of a debugger for figuring out why the code I've just written has dropped to pretty close to zero. Posted by: Adrian Howard at February 8, 2007 06:03 AMMy comment wasn't allowed for questionable content. Then my link to my comment posted on my own blog wasn't allowed for questionable content. Sufficive to say I agree with Erik and made a few of my own point about simplicity of tests. Posted by: Shane Courtrille at February 8, 2007 06:34 AMFigured out the problem. If you do a comment preview you can enter a URL to link to your name. Turns out that URL can't be a blogspot URL :) Here is my response: I can't come anywhere near Erik in diplomacy and politeness so I'm just going to say that I agree completely with him. If you feel most comfortable running your code every time in a debugger first, then by all means do so. But there is no need to get upset because those around you are feeling more comfortable using their debuggers less. One thing I will point out is that personally my tests are so specific and simple that it usually takes about 2 seconds of looking at one to verify it is what I want. Of course there are points where I still end up using the debugger. I do find that a large percentage of that time is with code that hasn't (inherited code) been switched (yet) to testable code. While I of course have to start up the debugger in my tests on the rare occasion it is just that, rare. Posted by: Shane Courtrille at February 8, 2007 06:35 AMCedric, As for tracing code prior to knowing there's a problem...I admire your discipline. I prefer liberal use of assert statements. But I have to admit that often times when I find a problem, I often step back and start tracing from the beginning (and adding more asserts) to make sure everything is as I think it is. -Erik (but not the same as the first poster) Posted by: Erik Engbrecht at February 9, 2007 06:42 AMSteve McDonnell has advocated stepping through every new line of code written. It's an excellent way to learning about bugs. Posted by: Chui at February 12, 2007 02:34 AMSteve McConnell has advocated stepping through every new line of code written. It's an excellent way to learning about bugs. Posted by: Chui at February 12, 2007 02:34 AMHello all, I can't help but think about this quote: 'Writing multi threaded applications is more fun than writing single threaded applications.' 'Debugging multi threaded applications is less fun than debugging single threaded applications.' :) Posted by: Anonymous Coward at February 13, 2007 01:33 PMErik wrote: No, typically I tend to look at the code first, and try to work out what's wrong - often I can do that based on the way that the test failed without going into the debugger. If I can't, then sometimes/often that means the code I'm testing isn't simple enough to start with, and after sorting out what's wrong in the debugger, I'll refactor it to make it easier to understand anyway. Suffice to say I'm in the "less time in the debugger" camp. In response to Erik's contention that less debugging implies poor tests -- that doesn't make any sense to me. One benefit of writing small, focused unit tests in isolation (among many benefits) is that when a test fails it's usually fairly obvious why it failed, especially if you run the tests often while adding and changing code. I've heard this called "localization of failure". It's not uncommon to be able to fix a bug caught by a focused test without using the debugger. On the subject in general, I recently started working with Ruby on Rails. There aren't a lot of great tools for Ruby yet, including debuggers. Without even really having a debugger, I've found that I rely a lot more on unit, functional, and integration tests (to use the Rails terms). Sometimes I do miss having a debugger, but I think that's happening less and less as I continue to grok the new language and new framework. And an increased reliance on automated testing is good for the project in the long run. That's not to say I wouldn't welcome a world-class Ruby debugger! They're a valuable tool and they do complement unit testing, but from personal experience I think there is validity to the idea that unit tests can ween you off your debugger -- or even help you quit cold turkey if you have to. Posted by: Jeremy Weiskotten at March 19, 2007 05:14 PMPost a comment
|