Xaprb

Stay curious!

Don’t change a constant variable

with one comment

A company for whom I have done some coding advertises their years of service on their website. Every year after the New Year, someone notices the dates are out of whack, sends around an email and it has to be fixed. It’s not quite hard-coded, if that’s what you’re thinking. It’s just that the wrong thing is hard-coded in the website’s configuration file, Config.asp:

Const YearsOfService = 31

I’ve seen someone update that variable literally every year I’ve been involved with the company in question. Today it happened again:

Const YearsOfService = 32

A moment’s thought shows there is something wrong with this code. YearsOfService cannot possibly be a constant, right? Unless it’s posthumous and the company will never add another year of service. The issue is that we’re holding the wrong data constant: the real constant, which will not change (hence the name) is the year the company began offering service.

I proposed the following code:

YearsOfService = DateDiff("YYYY", "1/1/1974", Now())

I got the terse reply “Go for it.” Of course I did. Why is this so hard? I can see missing the obvious once, but year after year after year? In a team of six or seven people? How can you explain everyone missing it time after time? I don’t get it. This is really, really easy. Even if you postulate that it takes a deep thinker to notice the incongruence about a “constant” that has to be updated, it doesn’t take a genius to notice a pattern after you do something really simple a number of times.

I really want to wrap this post up by saying “it only seems easy, but there’s a factor that’s not obvious, which explains the whole thing.” But I can’t. I don’t see any such factor. If you were hoping for some insight, sorry, I can’t offer it. *sigh*

Written by Xaprb

January 6th, 2006 at 6:25 pm

Posted in Uncategorized

One Response to 'Don’t change a constant variable'

Subscribe to comments with RSS

  1. Some time ago, I was bumming hard about what seemed to be a lack of enthusiasm among my co-workers, and the resulting mediocre work that is produced when you’re just not jazzed about what you’re working on. I was told: “It’s lonely at the top.”

    I guess it’s sort of self-indulgent to feel that way, but it is at least reassuring, like saying “keep up the good work.” At some point, there are rewards for working hard, taking what you do seriously, and dedicating yourself to being an expert in your field. When you finally find co-workers that are operating at the same level as you, you will be highly appreciated, and your team will be producing high-quality work.

    I can say that I deeply appreciated your expertise and level of committment to high-quality, maintainable code when we were collaborating — and I think we produced something great as a result!

    Sally Carson

    8 Jan 06 at 1:33 pm

Leave a Reply