Why to call a blog 'good enough code'? Why not perfect code? You don't want to have a perfect code?
Nope.
What? Are you serious?
Yes.
Let me tell you why...
We have all seen some good code. We have all seen piles of bad code. And some really really bad code. And we know bad code smells. But there is one code smell above all - perfect code.
Let me show you an example. I work in finance - sooner or later we will get there. But let me start with physics.
Let's say you are calculating amount of light Earth receives at any given moment.
public decimal CalculateLight(DateTime when)
{
/* ..... */
}
Sounds simple. You add up the sun, the moon, stars and you have the result.
What about solar eclipse? Lunar eclipse?
Ooops... Ok, I can fix that.
Really? And what if solar eclipse happens during a full moon? Will it still work?
... take a pause now ... what is your answer?
- Yes
- No
- Yes. It took me 3 weeks to implement correctly
Most developers will answer:
Well... No.... Sorry give me that 3 weeks..
But actually the correct answer is
- http://en.wikipedia.org/wiki/Solar_eclipse
Do you know already? This can never happen. Solar eclipse can only ever happen on a new moon.
Busted - you have been caught in a a trap of perfect code.
There are edge cases which are not worth caring about. Perfect code solves them all. Especially these which will never happen in real world.
Ok, fine. But why it is the worst code smell?
How much time did you spend on it?
How much code did you add?
How much slower is it?
And again - for what benefit?
And that's why good enough is more useful than perfect. Which makes is better.
And that's why this is about good enough code.
No comments:
Post a Comment