Scott Hanselman

But what price my soul?

November 11, '03 Comments [8] Posted in PDC | Speaking | NUnit
Sponsored By

Yes, it compiled.  It worked even.  Not only did it work, but it completely meets the client's requirements.  But somehow when I look at those particular lines of code (16 lines, in this case, with DataGridGirl's help) I wonder about the ramifications of this horrible algorithm on my immortal soul.

If you know me, or maybe even if you don't, you know that it has been said I have an overdeveloped sense of smell.  Specifically, Code Smell.  Often it's a gift and has served me well.  Other times it's a crushing weight as the schedule looms and I just have to buck and, well, write some crap.  (Of course, if it is totally with in spec, performance, it works, QA, etc, it's not crap, but you know.)

So my question to you, fair readers and fellow codesmith's, how bad do you feel when the pattern doesn't quite fit or that nested foreach/foreach/foreach nested a bit to deep? 

When do you know to let go? Some might say, “when it passes the NUnit Test!”  Others, who look at coding as much an art form as science might disagree.

I noticed a number of folks, from Don Box to Doug Purdy, at the PDC making GREAT PAINS to let the audience know that “this or that particular line of code is an abomination! Look away, look away from these alpha bits that hold all our pride and all our shame.”  I had to say I agreed with their evaluations.

What to do when you've built a great monument, but there's bird poop at the top that you're responsible for.  Does it take away from the accomplishment?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Tuesday, November 11, 2003 7:54:32 PM UTC
yes! oh yes! I swear, I think "what would Sam Gentile think if he saw this code" and just kill myself to make it work better on the inside even though on the outside my client will never know the different. This is also a lot of unbillable hours. But god, it's so satisfying. But ...uh, oh, I see a LIbra self-debate coming on. Back to coding.
Tuesday, November 11, 2003 8:48:02 PM UTC
Yes, I feel quite bad when I write something truly horrible. Usually, I try to refactor these bits into something that won't turn you to stone for looking at them. Sometimes though, I just have to leave it for the time being and maybe drop in a comment.

// this works, but I would like to refactor it
// must be a cleaner way to write this code

or

// this may look horrible, but IT WORKS.
// I call it my '72 datsun pickup code
Tuesday, November 11, 2003 10:06:49 PM UTC
I'm of two minds on this. On the one hand, I totally agree with the "anything worth doing is worth doing right" school of thought. One of my favorite book passages is in the fantasy series The Belgariad, in which the character Durnik, a blacksmith, explains to the young Garion why he's spending so much time working on repairing the underside of a wagon tongue that no one will see. Durnik explains that even if no one sees it, if he doesn't do the best repair he can, he'll know, and he'll be reminded every time he sees that wagon that he did not do the best job he was capable of doing. That story resonates strongly with me.

At the same time, the reality is that most, if not all of us, live in a world of limited time and other limited resources, and it's not always realistic to make one's code ideal in either form or architecture. So I think sometimes, "good enough", assuming that it really *is* good enough, needs to be the answer. I'm sure that there's some code out there that I've written that I would not be proud to have made public. But as you say, if it meets the specifications, performs acceptably, etc., then it's doing what it's supposed to, even if it's not the most elegant code possible.

My 2 cents.
Tuesday, November 11, 2003 10:27:34 PM UTC
"The enemy of good is perfection."
Wednesday, November 12, 2003 12:37:10 AM UTC
Trackback
http://thetechnologist.is-a-geek.com/blog/PermaLink.aspx?guid=760a2825-38e6-4bf2-a35c-5f9ecfa2bf51
Wednesday, November 12, 2003 12:37:30 AM UTC
For situations like this I have a copy of Funduc Software's search and replace utility and I create a nice and easy regular expression for every instance of my name in code as I may have put it there and run it changing the name to somone elses name like Glucose and presto change o it's no longer my problem. Seriously though right now I am dealing with a similar Frell'n situation. We have a release date and the code that going out shouldn't be. In fact it needs another week of QA at least. Two days of QA for a project that we have been coding on for the last month(s) is just nuts but the business unit is aware of it and it's going no matter what. Sometimes they make the choices but we are the innovators that come up with the cool ideas that make it work. As long as I can work out cool problems and stay abreast of current tech I dont mind if they force me to put out bad code. My sleep says otherwise but what the Frell.
pirklk
Wednesday, November 12, 2003 6:25:37 AM UTC
Oh yes, it bothers me a lot. Clean code is much easier to read, easier to alter to new requirements, and easier to show off, heh. People want the environments they work in to be both effective and elegant. I think it's similar to the usability and design issues a website faces. It's much more pleasant to use a website with good organization and an uncluttered interface. Just as the website is a web surfer's element more so than the browser or operating system, the code is the coder's environment more than any IDE. We just have the responsibility of creating it ourselves.
Thursday, November 13, 2003 4:55:11 AM UTC
This past week I've gotten to catch my breath and look over some of the old code I've written for my latest project. Often I catch myself thinking "What idiot wrote this code? Ah crap, it was me.". My code is always littered with comments like "need to clean up" or "This is really ugly, but it works".

I think that every coder always thinks they can re-write every line of code to be a little cleaner or more efficient ; Practical coders realize there is a point where you HAVE to release the code. You just have to balance the quest for perfection with the need to ship. It helps to realize that all programming is basically hacks and work arounds to little quirks and bugs in your chosen platform.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.