Code smell

Why is it that software developers leave their code lying out for a few days when it smells bad?

As a software developer I frequently find that I’ve written some code which I’m not happy with. Frequently. The problem is that it’s not always clear why I’m not happy with it. When this situation arises there’s usually some sort of amorphous feeling that what I’m looking at is not a good solution.

It works, but something about it makes me uneasy.

In the software world, this is known as code smell. When this situation arises you can either just go with it (after all, the end result is what you wanted) or have it peer-reviewed.

But here’s a strategy which a lot of experienced software developers do: walk away from it; mentally shelve it – even for several days.

I personally find that when I do this, then from time-to-time I mentally revisit the problem for a few moments (eg, while waiting for a tram, or when the adverts come on TV), an elegant solution brews itself.

Got a problem? Sleep on it

The proper term for this type of thought gestation is unconscious cognition, and it’s been proven to work. In fact, it’s a key process in learning languages.

A Dutch professor of psychology, Ap Dijksterhuis, experimented with three groups of people who were given a problem to solve. One group was asked to come up with an immediate solution, another group was given time to consider the task before providing a solution, whereas the final group was deliberately distracted before being asked to provide a solution. The solution deemed most satisfactory was that provided by the final, distracted group.

It just doesn’t feel right to me

And have you ever read a sentence which somehow feels wrong? You can easily comprehend what the writer is trying to convey but… well, it’s just not how you would have written it?

This is because the rules of grammar are not only learnt but also applied unconsciously. Consequently, one does not need to be aware of the rules of grammar in order to write correct grammar.

A case in point: me. I was able to read simple passages before I started school (and I started school at 4), and from a comparatively young age I read books, a habit which I’ve never lost. I went on to achieve the top grade for English exams in high school, and yet it was only a matter of months ago (in my mid-30s) that I found out what a preposition is. The subjunctive? I have no idea what that is. An adverb? I could take a guess. I’ve been taking German lessons for almost 18 months and I’m still trying to get my head around whatever the dative and accusative cases imply, and yet I can correct English speakers’ use of who and whom.

A case of trying too hard?

It turns out that a bit of simple distraction and giving the brain some time to itself is what we really need.

So the next time you find that you can’t see the wood for the trees, then I suggest that you head for the beach.

Image taken from this website.

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *