What is bad code? 09 Nov 2012
Bad code is code that is more difficult to change than it should be. This makes code that is more flexible to change better code.

If you keep making the code more flexible to change you’ll find yourself climbing free from the lava pits of horrible code into the swamps of poor code. Hard as it may be, stay determined. Despite the hammering of the rain you will trudge out of the swamps of poor code to find yourself at the edge of the murky forest of fair code. It will be hard to see at times, the fog will be thick and heavy, you’ll hear noises which distract you, but stay focused and determined and you will break free from the seemingly endless and impenetrable walls of the forest; through which you will find yourself entering into the sunny grasslands of good code. But don’t stop there. You’re too close to stop. Over a few more hills you’ll find yourself in the lands of great code.

There are a lot of ways to spot bad code with some being painfully obvious and others being extremely subtle. If this is all too black and white of a definition of “bad code” imagine that there’s a spectrum of code quality where the far left is horrible and completely inflexible; and the far right is code that is best described as a liquid, effortlessly forming around whichever situation arises. Regardless of where we are on this spectrum everything to our left is going to be worse than where we are while everything to our right is going to put us in a better spot moving forward (easier and more flexible to change). We shouldn’t be interested in moving left, not even a little bit. If we move left we’re making things worse off. It doesn’t matter if we move an inch or a mile to the left – things are worse off. Making things worse is bad practice, bad form, and ultimately bad code.

That’s why we should aim to make our code as flexible as it can be within the constraints we are given and within the best of our abilities. If we’re doing it right each day should allow us to move a little bit farther to the right in one way or another.

blog comments powered by Disqus