Scripting News: How long does it take to find a bug?

I had a working Find command, but needed to factor the code so that I also had Find again. One has a UI, the other just repeats the previously specified search. The code that does the finding should be the same in either case. Splitting off common code is called factoring.

After factoring, I tested the Find command. It works.

Getting ready to test Find again, I paused, thought to myself — there’s a chance it might work the first time. Bad idea. Of course it didn’t. No big deal, I’ll just step through the code, watch it fail, and figure out what needs fixing.

I notice a value is undefined. Weird. I repeat the experiment and watch it get its value. It’s calling a routine that’s been called millions of times. It works as well as anything. I seriously doubt it has any bugs. But there it is returning an undefined value.

It never occurred to me to check if the thing I’m asking for actually is undefined.

Two hours later it finally dawned on me, that was the problem. I had been assuming undefined was the wrong answer. It was the right answer. There was an edge case which I was hitting now, which had nothing to do with the Find command, that was causing the value to be undefined. I added a bit of code that checks for the condition, and fixes it, and voila, it all works.

Moral of the story, the bug was available to be discovered within minutes, had I just asked the right question.


About Dave Winer

Dave Winer, 54, pioneered the development of weblogs, syndication (RSS), podcasting, outlining, and web content management software; former contributing editor at Wired Magazine, research fellow at Harvard Law School, entrepreneur, and investor in web media companies. A native New Yorker, he received a Master's in Computer Science from the University of Wisconsin, a Bachelor's in Mathematics from Tulane University and currently lives in Berkeley, California.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s