My Octopress Blog

A blogging framework for hackers.

The Programmer's Time Paradox

At the beginning of this week I started work on a new feature. For the purposes of this post it doesn’t matter what the feature was, but I started in on it on Monday and things went extremely well. I was in the zone. It’s hard to describe, but I think if you’re a programmer you’ll understand the feeling. I started out with just the right amount of testing in the right places, built something simple and added on top of it, while refactoring periodically as I discovered new angles on the problem. Everytime I moved forward, I was able to run my tests and tell immediately that my last fix had broken something. I was moving forward in small steps and it was all falling together nicely.

And then I got greedy. I suppose it makes me a dork to admit it, but I was having fun. I had been somewhat behind on the feature because I was debating on a couple different paths, but now that I had chosen, I was moving forward with wreckless abandon. It’s somewhat intoxicating to be in the zone. So, I pushed myself hard. I worked from around 9 AM until 1 or 2 in the morning every night for 3 days straight. (I work from home, so it’s a bit easier to work later like that)

This morning I woke up begrudgingly. The comforter was very, very heavy. It was the weird programmer kind of fatigue, where you’ve done nothing but sit on your but all day, but your mind has been going too fast for too long, so you feel mentally exhausted but physically fine. When you hit that point, no amount of coffee is going to make it better. Now, I’ve been on some pretty hellish death marches before. Some of them spanned months, so it’s not like working hard for 3 days is all that terrible. But the programming gods are vengeful. I might have been tired, but I was excited to get the feature working. I was in the home stretch. My sister is coming to town this weekend and it’s her first time in Chicago since turning 21, so I wanted to get this thing done and party like it was…2003?

So I got sloppy. I ran into a weird bug. It was a NullPointerException with no stack trace. Which sometimes interchanged itself with an InovcationTargetException. When you see something like that happen, it’s time to stop the production line. I should have stopped, immediately, and attempted to recreate the conditions in my testing setup. I had a perfect, isolated, test suite setup where I could have recreated this thing in a controlled environment, but I didn’t do that. Instead, I fiddled with idea after idea. They were all well informed, reasonable things to be trying. But when you’re doing this kind of thing inside your application, there can be too many factors. Production code is complicated, and there’s just too many variables.

At around 6PM I stopped myself, and did what I should have done in the first place. In an integration test, I slowly recreated the problem, piece by piece. Within 15 minutes I had found the problem. I forgot to put an annotation on a particular class.

I. forgot. an. annotation…..$#$%#$%#$!!!!!!!!!!!

I suppose I could get mad at the guy who wrote the open source framework I was using. But I would be one heck of a hypocrite if I did. I can’t imagine how many people have been in the same situation with Spring Batch, and probably felt the same way about me. I hit a scenario he didn’t think of, so there wasn’t specific error handling for it, and the results were nondeterministic.

No, I was tired. I pushed myself too hard and I made a stupid mistake, and the funny thing is, I lost all of the time I had saved by working so much! Awesome.

And when has that not been the case? I can’t think of time where I worked too many hours and this exact same thing hasn’t happened. I was tired and made a stupid mistake. A mistake that I would have easily caught if fully rested. And that mistake had cost all the time I had spent working late. And it’s compounded by the number of people overworking themselves. The more people doing it, the worse the effect is. Because your stupid mistake made while trying to fix someone else’s stupid mistake quickly snowballs.

But sometimes, it’s just hard to grok. I don’t think the human mind is fully capable of thinking that way. If you’re running somewhere, running faster gets you there quicker, baring the limits of endurance. But overall, if you can run faster, running faster will get you there sooner. Or at least is seems that way when you’re coding at 1 in the morning on an interesting problem. And I know all about sustainable pace, and I agree with it fully. And I wasn’t under the spell of an evil project manager either. It’s a small company, and I’m the CTO. The only drive I have is to get features done quicker to support our sales efforts. And I know, from personal experience, what happens when programmers work unsustainable paces.

You know what it’s like? It’s like white castle. At least once or twice a year I’ll decide eating at White Castle is a good idea. I may or may not be sober when I make this decision, but I make it anyway. And I pay for it. The next day you wake up and you *know* you made a terrible mistake. And for days, maybe even weeks, you’ll swear to never eat at white castle again. But then you’ll be at your cousin’s wedding and there just so happens to be a white castle within walking distance, and the terrible cycle repeats itself.