David Caulfield

6 Simple Ways to Create Clean Code

Wouldn't it be great if we could all create clean code to a high standard from the moment we begin programming? If we could create clean and simple code that anybody could read, can you imagine the time saved on both an individual basis and on a company level?

When I began to write code, it was immediately clear to me that there are, on average, at least three obvious ways of going about a problem. If you think about the problem for longer and go into some research, then the number of solutions could go right into the double digits. Then we need to worry about which solution will yield fastest results in a short space of time, and how long will it take to code up. While doing all this, you need to write simple, clean, maintainable code. This is very difficult.

Or is it?

In fact, you can create readable and simple code from the get-go with just a few pointers. By implementing the points in this post, I was able to turn a lot of my code from a pile of spaghetti into a well-tailored suit.

In this post, I am going to show you exactly how to create great code that others, including yourself, will be happy to read and maintain long after you are finished with the project.


Beginner Coders vs. Expert Coders

When I began my coding career, I wasn't sure what the difference between a beginner, intermediate and expert coder was. All though these lines are subjective, there are some certainties that we can extract on the difference between stages.

A beginner is somebody who studies the coding language but isn't very sure about how things work or in what way they work. A lot of code gets copied and pasted from the internet without much knowledge of how it works. Often it is just a case of trial and error in seeing whether or not something works.

In contrast to this, an expert coder understands every line of code that they write. Code will rarely get copied and pasted, instead the expert coder has the ability to extract ideas and formats from the code they are reading. They can then apply these extracted concepts to their own project.

I once heard a very good statement about coders. It went something like this:

Juniors build complex solutions to simple problems. Intermediates build simple solutions to simple problems. Experts build simple solutions to complex problems.

In progressing from stage to stage in your coding career, one thing remains a constant: you need to be able to write good, clean, readable and simple code. No matter what your current skills are, you cannot progress further if you do not write clean code.


Write Clean Code

The following five posts will go through briefly what I believe to be the fundamentals of writing simple code. These are all points that you can start practising straight away, if you do not do so already.


  1. Use Clear Names in Your Code
  2. Silver Whitespace
  3. Short Methods
  4. Short Classes
  5. Commenting
  6. Use Libraries



After reading these articles, you will hopefully be able to put the pointers to good use, whether it be in a simple method, or developing the rest of your application using clean code.

0 kudos