What's in my head?

The random ideas, questions, and thoughts that enter this feeble brain.

Wednesday, March 16, 2005

28 Characters . . .

So on Friday my manager came up to me and said "Hey Johnny, there is this trouble ticket in your queue that needs to be resolved as soon as possible, it's very important." Noting the weight of the statement, I agreed, "I'll start on it immediately".

Let's see what I can say without getting fired... hmmm OK, the problem was that our code was not populating fields as it should have. So what? Well, this means slows the reps down, which can get customers angry...which is perceived as bad Customer Service...is not good for the company... Let's just say the company deals with a large number of Customer Service reps and an incredibly large number of emails on a daily basis.

Ok, so there's the motivation.



I was going to blab about all the things I did to find the problem, but it ended up being a story of same old same old: Repro the problem, read the logs, attach a debugger to the front end, attach one to the back end, all good. How about the middleware technology? All good.

To make a loong story short, I found the problem today. I can reconstruct it into wont-get-me-fired code like this:


if( !alreadyDidSomething ){
doSomething();
alreadyDidSomething = true;
}


A coworker comes to my cube and tries to help out. I was running the debugger again, and when I come to the abovementioned lines he asks "hmm where is that variable initialized?" At this exact moment, I recalled a discussion I had with a friend at school after I had found a bug I caused in our OS. "I forgot to init this variable..." "JOHNNY!", she shrieked, "how many times have you hit this problem. INIT YOUR VARIABLES!" Since then I have this great habit of ensuring that all my variables are initialized before use. Sounds trivial, but when the number of variables grows, and the complexity of the system grows, it's easy to miss one.

So it turns out that alreadyDidSomething was never initialized to false. There was the bug. The variable came to life with whatever was in memory at the time. This problem lead me to a lot of dead ends while debugging, because at times the code actually worked! The solution? When the object containing the variable is instantiated, I set alreadyDidSomething to false, like so: :alreadyDidSomething(false). (This is in the context of the constructor's signature, in C++.

I tested, and things seem to be working now. The errors in the logs are gone, and the results are always what I expect.

Now the name of the variable and other information has been altered to protect my job, but all in all, 3 and a half working days have been spent on 28 characters. Humbing. What would you have paid a programmer for fixing this?


This could lead to a whole discussion on compiler warnings and code reviews, but I'm tired.

0 Comments:

Post a Comment

<< Home