Here in the south (I live in Alabama) we have a saying “quit straining at gnats”. A gnat, by the way, is a very tiny bug that proliferates during the summer and tends to fly in your face when you walk outdoors. The saying essentially means “you’re working very hard to get rid of something very small”.
In Episode 300 of Dot Net Rocks (a great episode) Richard Campbell tells a great story. The short version is Richard is called in to look at a computer that’s having problems. It’s the mid 80’s or so, and this PC is responsible for downloading financial info. Every hour the computer reboots itself and they have to go start it all back up. He says “I can fix it, but it’ll cost you 3 grand”. Client sputters and says they’ll think about it.
Two weeks later he gets the call “OK, you got the 3 grand, come fix it.” So on the way to the client he stops and spends 1500 bucks on a new PC, puts it in place at the client, copies all the old software over and boom it’s up and running perfectly. As he’s walking out the door, check in hand, he’s asked “what was wrong with it?” “Heck if I know.” Richard replies. “But the problems fixed.”
It’s a great story (and much funnier when you hear Richard tell it), but it illustrates a great point. All too often we obsess over some problem, and lose sight of the desired result. All too often we focus on some piece of code, trying to come up with the most “elegant” solution, or frustrate ourselves over some piece of code instead of tossing it and rewriting.
I’m not saying write bad code, or write sloppy code in a hurry just to get it done. I am saying when you run across a problem, don’t get so invested in it that you don’t see alternatives. Time and again I see a developer getting stuck on a problem, trying to fix some arcane piece of code, or spending hours to get that extra millisecond from a SQL query.
When you run across that road block, take some time. Push back from your computer and think for a moment. Think what the true outcome of your application is supposed to be. Not “what will the program do” but “what will the program do for the user???” Think about how best to achieve the users goals.
As Campbell pointed out several times in the episode, when you are writing software for a business it’s all about making money. Your program should either make or save the company money in some fashion. Whether it’s by crunching numbers in a faster, more efficient way than a human could, by providing information in a more timely fashion, or any of a thousand other scenarios. Never lose sight of the fact your software is to provide a solution, and not being written for artistic purposes.
Don’t get so lost in the code that you wind up straining at gnats.