Every so often, we write or review code that’s a bit of a clunker. At the time we probably go something like “never mind, there’s no time to do this better, let’s just move on”.
And then we notice that same clunky code again a bit later… but the decision was already made.
Then the code is nearby some other problem, but it’s not really the cause so we don’t do anything.
But we keep noticing it. We may even put some comment on it, concerning things that could maybe be done differently if there were only more time. But it’s really not doing any harm, so we leave it.
But keep noticing it here and there.
What Sort of Code Is It?
This is the sort of code which eventually finds itself involved in situations where someone slaps their head and goes “I can’t believe I didn’t notice that!”.
This is the sort of code which hides in plain sight, causing you a problem you notice, yet still fail to notice. You’ve explained it away, and accepted it, despite it being a recurrent nightmare.
This Code Is…
In the story where I realised late that some code was taking forever to process even a single record, the code in question had a comment like this over it:
// This code is my biggest shame
We all thought the developer was being cute… they were not… it was a problematic bit of code.
What To Do?
Don’t write code you immediately regret. Or hack something together, get good tests in place, and then refactor/rewrite once you know what you should have done.
If you spot dirty code like this, try to make time up front to solve it. The mid-term cost is probably larger than the short-term saving.
But if you’re late in the project cycle, and it’s a nest of danger, then maybe it has to be left until there’s a genuine risk.
But keep an eye on it… because that code is definitely up to something quite not good!