Click here to show or hide the menubar.

Home >  Archive >  2010 >  August >  1

Previous / Next

Debugging 101
By Dave Winer on Sunday, August 01, 2010 at 11:57 AM.

A picture named bikewide.gifI love that David Weinberger is narrating his fumbling programming work on his blog. It's great for a lot of reasons. permalink

Everyone goes through what he's going through. permalink

You never stop going through it, even if you've been programming for 37 years, as I have. You'd think after all this time I would remember the basic lessons I learned the hard way when I was in my early 20s. But nope, I often forget them. permalink

It's very useful for me to read his narrative. I'm going to teach this stuff, and I have to remember that what seems second-nature to me now, once didn't. permalink

One of the things I talk about with everyone I meet at NYU if they're willing to listen is that we're not teaching programming and we should be. I think every person who graduates with a bachelor's degree should have one semester of programming, just as they should have one semester of journalism.  permalink

If I ever get my book together, there will be a chapter on programming in it, where we'll cover the basics. Logic, looping, variables. I seriously think we can get political science students to experience a teeny bit of the magic of programming. It'll be a challenge for sure. permalink

But it's a serious situation because there aren't enough students taking up computer science. New York wants to become a tech center, but it'll never happen as long as there are so few programmers graduating from our universities. Another way of saying this is that every student graduating with a compsci degree is much sought-after. They have their choice of jobs. This, in a major recession. permalink

A picture named bike.gifNow, my advice for David, and anyone else who is staring at code wondering how it could possibly be behaving as badly as it is.  permalink

Of course you're going to think it's the system that's screwing up. We all do. But that is so rarely the cause of the problem that it pays to put the theory aside and get the computer to reveal its logic to you. It's coming up with what you think is the wrong answer, but when you finally figure it out, you'll see why it's the right answer. You can't move on until you see this. permalink

So step through it in the debugger, and watch what it does with your data. Eventually you will see it do something that isn't what you expected. Now figure out why and change the code, and test again. permalink

I once stared at some code that was supposed to return the value 26 but it was returning 251. Must be a bug in the math processing code, because how could 25 plus 1 yield 251. But it did, ever damned time the code ran. Until I realized that the 1 was a string and the 25 was a number and the language coerced the number to a string so it could concatenate them. What was imperfect was not the machine, but my understanding of the machine.  permalink

BTW, I can only remember one time that a problem turned out to be a bug in the system. I spent a week chasing a bug in IBM's Pascal compiler in the early IBM PC. Of course there was no way to file a bug report, so once I understood what it was (I had to look into the code it was generating) I just worked around it.  permalink

A picture named kong.gifAnother time, there was some bad memory in my system. This was in the very early days of PCs, when there was no memory management. So I put a comment around the bad memory in my source, and was very careful not to add any code above it -- in all my source files.  permalink

Very early in my career as a programmer, I had an office in the Empire State Building, on the 39th Floor, with windows that open. I was there late one night, trying in vain to figure out which of the computers that was running my code had the bug. My problem was I had no idea how to approach the problem. That's 98 percent of the battle, clearing your mind, rolling up your sleeves, accepting the responsibility that it's your bug not some programmer in New Jersey, or the guy who wrote the operating system. I remember thinking, staring out into the NYC night that they shouldn't put young programmers in skyscrapers with windows that open. :-) permalink

RSS feed for Scripting News
This site contributes to the scripting.com community river.


© Copyright 1997-2012 Dave Winer. Last update: Sunday, August 01, 2010 at 5:03 PM Eastern. Last build: 8/26/2012; 5:52:00 PM. "It's even worse than it appears."

RSS feed for Scripting News

Previous / Next