Wednesday, 9 July 2008

Sohail, it doesn't work anymore

Everyone has a story about when they were younger. For example, Joel Spolsky talks about his time in an army bakery (or something like that.) Sometimes, the stories are quite pathetic like Al Bundy and his high school football team. I am neither as exciting as Spolsky, nor as pathetic as Al Bundy (though I'm sure the latter is up for debate.)

This story is about something that happened to me when I was younger that made me who I am today.

I started programming quite late by geek standards. I was either 11 or 14 depending on whether you count batch files as programming. But I loved it. And when I got tired of programming, I'd program some more in FastTracker 2!

For a while, I had a job as a pharmacist's assistant. This particular pharmacy had the option for delivery of prescriptions and other general items. The deliveries were done in the evening and were done by two very friendly guys named Krish and Sam.

Part of my job here (besides preparing the methadone!) was to add up all the deliveries that these two guys did within some period of time and summarize for the boss. It used to take me hours in a busy month as it required use of some large Excel spreadsheet. So I resolved to solve that problem with my programming chops. I got the owner to agree to pay me hourly (wow, $10/hour!) and he told me not to spend "too much time" on it. So I guesstimated 40 hours until I would be able to deploy the application. He was fine with that.

I was mostly right but near the end of it, while I was testing with the users (me), it turned out some other data collection was necessary. After discussing with the boss, he said it was important but not to spend "too much time" on it. By then, I had come to realize that "too much time" means "don't charge me more than I want to pay you." So I added it quickly, and it was done.

I deployed the application in December of that year to rave reviews from the boss. I'm not sure if the other employees cared that much but I know that it made my life easier and the count of deliveries more accurate so I was happy.

Due to other responsibilities (I think it was school?), I had to reduce my hours at the pharmacy. That was around June. I had trained the other people to use the application and it was becoming quite necessary for them to use if they wanted to retain their sanity.

Fast-forward to November. I get a call. "Sohail, it's not working anymore." "Crap", I thought. What did I miss? I went into the pharmacy and fudged around in the flat files to see what could be wrong.

It turns out that one of the data files was being named incorrectly. Can you guess which data file? Yes, it was the one I had added last just before I completed the project.

I think I spent about 10 unpaid hours debugging the problem at home while studying for exams/finishing projects. It came down to this (in C++, I don't really recall the language):

// data1.cpp
const char * months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

// data2.cpp
const char * months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov ","Dec"};

Can you see the problem? In the second instance, I added a space after "Nov". So while data2.cpp was saving "Data2Nov Year.file", data1.cpp was saving "Data1NovYear.file" and the code that summarized the data was trying to open "Data<N>NovYear.file".


I fixed this bug and apologized to the owner. I explained why it happened and that I fixed the code duplication. The boss said that he thought I should get an award for this software (a big ego boost!) and wondered if he could sell it to other people. Apparently he had been raving about it to his other pharmacist buddies. I don't remember what I said to him about that (something about me not having enough time to modify it to be generic enough as Sam and Krish were hardcoded!) but I really learned something that month.

Fortunately, in this case, things turned out alright. So I swore to avoid similar problems in the future in case future clients were not as forgiving. How did I do this? Quite simply:

  • Thorough testing

  • No copy-and-waste

My business cards have always had some variation of this. The current incarnation has something like "Do it once, do it right." Corny, but conveys my philosophy quite well. I will work very hard to reduce code duplication now. I try my best to write a test for each function/class that I write. Yes it is hard work. Yes it takes time. Quite frankly, software is hard. But in the end, I get very few calls saying "Sohail, it doesn't work anymore."

And no, you are not allowed to put a comment on this post saying "Sohail, it doesn't work anymore" :-)

1 comment:

Manki said...

Interesting post :)