Code Craft
The art, science and craft of writing quality software

Aug. 15, 2005 - The smell of wet dog

If you´ve ever owned a dog (or had a friend or relative who did) you´ve had this experience.  The door opens and in rushes the smelliest and foulest creature you can imagine, dripping wet or maybe covered in mud.  On its face is a look of guilty pleasure.  It knows it has done something wrong, but it still expects that somehow it´s ok.

 

People are like that too, or more specifically I am.  Anyone who knows me has seen it happen; a real problem is being discussed and a mischievous grin seeps out and covers my face. The next sentence starts out like this: "This is really evil, but you know what we could do?"  By the end of explaining a horribly nasty hack that would solve the problem I usually end up saying something like this, "no.  That´s way to evil; definitely don´t do that."  Like the wet dog, I´m savoring a private guilty pleasure (if only as a thought experiment).

 

Having confessed a sin let me now retract my confession.  Coming up with hacks (even evil ones) is one of the most useful skills any developer can have.  Like other venial sins (laziness and sloth) even evil hacks have a place in code craft. 

 

How can this be?  The key comes from a rule good chess players live by: first find the best move and then look for a better one.  When you find an evil hack there is frequently the grain of a good idea lurking in the background just waiting to emerge.  Ask yourself, "why is this hack evil?"  If the evil can be done away with and the good left intact you may have found a great solution.  

 

Another reason that thinking evil can be good is that it can be a key to figuring out why the problem is so hard in the first place.  Often the idea at the base of the hack is a hint that tells you what's not right about the system as a whole.  So the evilness of the hack is tied to the evilness of the environment in which it is being placed.  Solve the environmental problem and the hack is no longer needed.

 

The last reason that coming up with evil hacks is good is that sometimes they are actually the best solution.  This is very rare.  If you find yourself using the evil hack frequently then you are using the wrong kind of laziness.  When you first thin sliced the problem your instincts told you it was a bad idea and you need to trust that.  Rarely, detailed analysis suggests that the apparent evilness isn´t relevant in this particular case and the hack really isn´t so bad.  Other times, you just cannot come up with a less evil alternative that is viable.  In these cases the evil hack is what you´ve got so run with it.

 

Post A Comment!

Share and enjoy
  • Digg
  • del.icio.us
  • DZone
  • Netvouz
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb
<- Last PageNext Page ->

Kevin Barnes

Code Craft is the place for my thoughts, rants, ideas and occassional jokes on what it means to write code, why some people are better at it than others, and how we think about software in general.

Links

Home
View my profile
Site Feed (RSS)
Archives
Email Me
StorePerform
TechNexxus
Soul Craft (my stories and discussions)
My Wall

Joel on Software
Paul Graham
Patric Logan
Martin Fowler
Free Blogs
Free Blog



Copyright (C) 2005, Kevin Barnes. All rights reserved.

portfolio