Tesugen

Hard-coding stuff (Irrational Software)

I often find myself in disputes about whether or not to store metadata (or data for that matter) in the database. My opinion is that you should store it if it provides any value – not just because someone on the team is worried that sometime in the future, the value needs to be changed really quickly – so quickly that you won’t have the time to do deploy a new version of the software.

Other programmers are of the opinion that metadata/data never (ever!) should be embedded in the code – or hard-coded, which is the word to use if you want project leaders or management on your side – how could cementing the data within the code, so that you can’t get it out be of any good?

There’s a pattern called Shearing Layers, which is part of the Big Ball of Mud set of patterns by Brian Foote and Joseph Yoder (see also my post on The Selfish Class) and in this pattern, software is regarded as consisting of layers that change at different rates. They write:”Things that change most quickly migrate into the data, since this is the aspect of software that is most amenable to change.”

When I read this pattern, I pictured change being a wheel that is spinning, with stable (as in not as frequently changing) stuff staying near the hub, and as things change, they slide along the spokes of the wheel closer and closer to the rim. The rim is where the data is – that is, things that change most frequently. This picture was so strong that I believed it was in the original text, but it wasn’t. I’m not sure whether I’ve read about it in some other article.

Anyway, the point is that making a hard-coded value soft is often very cheap (If it isn’t in your project, then put it in the database right away!) so you might as well do it later. The more things you make soft, the more complexity you add to your software, and you don’t want unneccessary complexity. It also takes time from other things. But I’m not suggesting you should put the hard-coded values all over your code, though: the general rule still applies that says you should remove duplication in your code.

The above was posted to my personal weblog on June 6, 2002. My name is Peter Lindberg and I am a thirtysomething software developer and dad living in Stockholm, Sweden. Here, you’ll find posts in English and Swedish about whatever happens to interest me for the moment.

Tags:

Related posts:

Posted around the same time:

The seven most recent posts:

  1. Tesugen Replaced (October 7)
  2. My Year of MacBook Troubles (May 16)
  3. Tesugen Turns Five (March 21)
  4. Gustaf Nordenskiöld om keramik kontra kläddesign (December 10, 2006)
  5. Se till att ha två buffertar för oförutsedda utgifter (October 30, 2006)
  6. Bra tips för den som vill börja fondspara (October 7, 2006)
  7. Light-Hearted Parenting Tips (September 16, 2006)
Bloggtoppen.se