Owen Plimer

Software with passion

The importance of readable code

We have all wondered at some point or another why we need to make our code make sense to read. But keep in mind, you will probably be the next person to look at it.

The importance of readable code

We have all wondered at some point or another why we need to make our code make sense to read. But keep in mind, you will probably be the next person to look at it.

"Readability of code is now my first priority. It’s more important than being fast, almost as important as being correct, but I think being readable is actually the most likely way of making it correct." Douglas Crockford

The importance of clean, readable code

There is a simple saying that I have heard before, "Be nice to the next person to look at it, because it will probably be you" and this saying perfectly encapsulates issues that exist in many software projects. If the code makes sense to you, great. But does it make sense to anyone who has never seen it before? Will it make sense to you in a months time?

There is a way of writing code which helps to solve all of these issues and more. This is called clean code. I have no intention to get in deep about clean code today, I am only going to focus on the comments rules of clean code.

When writing code, you should always try to make sure that your code explains itself without comments. If your code tells you what it does you can eliminate the guesswork associated with opaque code. For an example, if you have a function that adds two numbers, call it add2numbers not a2n or even worse a.

You should never write a comment if it adds nothing of value. If you feel the need to write a comment somewhere, stop and think about what you can do to make your code easier to read. Almost every comment you write can be negated by making code simpler. Also, please do not be that person who writes comments for the sake of it. Please. If you have a function that will break everything in the world if you change it, you should probably write a comment to say that. Because if you leave dangerous code laying around and someone breaks it, you will not be popular with your co-workers.
It is inevitable that you will want to remove a piece of code at some point, for testing or other reasons. When you do this, just remove it instead of leaving it commented out in your source code. Leaving it in your source is messy and distracting which takes away from the clean code principles.

While clean code is not mandatory, it will make your life so much easier. Code you write now might make no sense what so ever in a months time, or to the next engineer who gets to read it through. So why not make it easy for them (or you) to understand, letting everybody get on with making great software and spend less time figuring out what code is supposed to be doing. For a more detailed analysis of the clean code principles, take a look at This GitHub Repository. It has a lot of useful information on it which will help make your life easier!