Friday, February 8, 2008

Pride of Ownership: Euphoric, Powerful, yet Dangerous Programming Nunchucks

Have you ever sat at your desk and banged away at a chunk of code, and after hours of toil, gnashing of teeth, checking online, and asking other developers, you finally end up with an awesome piece of code? Remember that euphoria that you felt, looking at that most raddest code, thinking about how awesome it was? I bet you even made up excuses of why you should tell other people about it, just so they could look at it and then regard you with awe at the code you wrote.

If you've ever felt anything remotely like that, then you have experienced pride of ownership. You looked at your code almost like a pet or a child, and you guarded it jealously against heretic naysayers desiring nothing more than to refactor you code, saying by implication that your child isn't good enough!

I happily admit to this. I once wrote a piece of javascript that was so rad that once I fully realized just how easily, elegantly, and fully it solved a business problem, I literally wanted to ask myself out on a date. Even my hero, James Hetfield, would have been impressed.  I showed other developers my little javascript function, just "so they could be sure to use it if they needed it."  I marveled at my little codeling.

There's nothing inherently wrong with feeling pride of ownership in your code.  It's a good and healthy sign that you actually take pride in your work.  Feeling good when you write especially good code is a sign that you do in fact like your job and that you should probably keep doing it.

Personally, I think taking pride in the work you do is one of the most important aspects of any job, but especially so in software development.  Writing excellent code requires a fair amount of self-discipline.  This self-discipline involves not cutting corners just to make features work, not short-changing oneself in the design phase just so one can begin coding, and knowing when to stand firm about a decision.  Software development can be such an exact science that taking pride in doing it well constitutes a desire to write good code.

Having said that, there are two pitfalls to pride of ownership.  First, how many times have you written that one piece of angelic code and then tried to use it everywhere, even if it wasn't applicable?  That pride of ownership gets to you and you just want to use it willy-nilly.  Maybe it's a robust piece of javascript, maybe it's a really awesome DAL wrapper class, maybe it's just a single method that solves a problem thought to be unsolvable in any elegant way.  However, you have to realize it for what it is:  A piece of code that solves a specific business problem, not a be-all end-all solution to every problem you'll ever have.  Learn to use your new-found lovely code judiciously and only in places where it's truly applicable. 

The second pitfall of pride of ownership rears its ugly head when you've spent so long working on one piece of code that you become committed to it.  You've spent so long working on this piece of code that, by golly, on your mother's grave, you will finish it!  No matter that the algorithm wasn't well thought-out, no matter that the code is hard to follow, you will finish it, because goodness forbid the last three hours you've spent developing this code go to waste!  In the past, I've found that when I've slogged through those situations and finished the code, I was usually left with something of which I wasn't overly proud.  It is much better to scrap the code and start over writing something easily-read and maintained that you will be proud of.  Your boss might get irritated, but he will be more irritated if you submit crappy code.

Remember the two pitfalls, but always write code that you'd be proud to show someone else!