top of page

Clean Code

Clean code can be defined as code that is easy to read like a book where each word transforms into a picture that can be visualized like a movie. In summary clean refers to source code that is readable by humans. The concept of clean code exists due to the challenges and failures brought about by bad coding practices.

Several companies in the past were able to create applications that got popular among lots of users, however after multiple updates/releases the number of bugs kept increasing and eventually the audience got frustrated and stopped using these apps. Eventually these companies went out of business however when the software engineers were interviewed they reported that the product was rushed and as more features were added the source code became more unmaintainable.

The bottom line for clean code is that code that works is not always done, the work of a programmer is not only to create a program that solves a particular problem however how the program solves the problem should also be of importance since in the long run the company, clients, users and coders will have an easy time interacting with the program.

Bad coding practices

There is a lot of power in writing bad code for it has the ability to bring an organization down. Some of the popular excuses for writing bad code are:

· As a programmer I have less time to do a good job and my employer would be angry if I take more time to clean up my code.

· As a programmer I am tired of working on the program since it’s less interesting and I want to get over with it so that I can handle more interesting modules

· The programmer can procrastinate cleaning up the messy code and keep pushing it for some other time causing the product to get to production with unsolved bugs.

During programming as the code mess keep building up the source code becomes harder for the developers to maintain which in turn slows the developers down. The more time spent by the developers working and solving the messy source code, the slower they get with time which continuously decreases their efficiency.

Clean code practices

Robert C. Martin who is an author and a master of writing clean code provides insight towards writing clean code in his book titled “clean code” which was released in 2008. Martin describes the best practices and also highlights the poor practices and admonishes those who fail to recognize why and how those habits are bad.

Martin’s book is at times referred to as the bible of software development due to all the insights uncovered in the book. The book provides definitions to various software luminaries and after reading the book the attributes of clean code could be summarized as the following.

1. Clean code is simple

The code should not be necessarily simple in terms its system level or algorithmic complexity however it should be simple in implementation. The sleights, hacks and clever tricks used in programming should only be for fun however during real product development the source code should be properly implemented avoiding tactics that diminish the source code’s long-term value. The same case applies for long winded source code that usually takes forever to get to the point.

2. Clean code should be readable

It is always advised to use common standards and conventions during programming. Conventions such as structure, spacing and naming should be constantly used within the entire source code, Failure to these programmers will have a hard time during maintenance and will fail to understand the original author’s intention for the code. Some conventions may seem dogmatic and may lack expressiveness e.g. use of camel casing for the naming of variables in JavaScript and use of Pascal’s casing for naming of classes in python however these practices help to make the code communal rather than arcane.

3. Clean code should be tested

It is very difficult to write perfect code that’s bug free and even if the code is bug free it is not always guaranteed that the code won’t break later. Writing clean code means that the written code should be tested frequently whenever there are core updates such as operating system updates to ensure that future users will be confident that they are interacting with something that works. Moreover, whenever changes are made there should always be a readymade test suite to ensure that nothing broke.

4. The code should be considerate

code that is not designed having in mind the concern of future users does not respect their time therefore clean code should always be well commented without the assumption that future developers are as intelligent as you are and the documentation and comments should go out of its way to help them.

5. Clean code should be practiced

In order to be a master of clean code, the programmer should have good muscle memory, and this is best achieved by constant practice just like playing an instrument, frying an egg or kicking a ball. The best way to learn about clean code is to write clean code and retain the skill. Programmers should ensure that they practice writing clean code even if it’s a personal project that no one will ever see.

6. Clean code is Solid

Good code should be as solid as it is clean. This implies that proper code indentation should be enforced even if the programming language used Is not affected by improper indentation. An example is HTML, during development of webpages in HTML it is important that the parent tags and the children tags are not in the same level of indentation. This makes source code look neat and highly maintainable.

7. Clean code should be relentlessly factored

According to Martin, clean code should be kept in a constant state of refactoring. This should be done with a well-designed test suite and the code should be backed up so as not to worry about breakage of the code. Tools such as Git version control should be used to track changes in your code and to easily roll back to a previous version in case of breakage.

If we take martin’s book as a reference, the characteristics and attributes of what makes up clean code could multiply and grow exponentially however the summary provided by this article is a good place to start. Adhering to all mentioned qualities requires constant attention to detail, persistence and willingness to accept that what you wrote yesterday can still be improved even if it worked just fine.

Clean code practices imbues a good mentality to its readers and also the developers for it promotes craftsmanship and saves the pain of tomorrow since code does not only belong to individual but to the community that might have to maintain it in a few years to come.


In summary it has been discussed about the gravity of bad code and how powerful it can be in terms of the problems it can later bring to a company or a project.

It is also important for programmers to be professional at their work which involves a lot more than just jumping straight into coding and coming up with a program that solves a problem however certain principles should be adhered to ensure quality of the end product.


Robert, C 2008, Clean Code, A handle book of Agile software craftsmanship.

Bullock, J. 24 Jan 2014, Clean code 5 essential takeaways [online] available at: (accessed date 12/8/2018)

Vuorinen, C. 19 Apr 2014, What is clean code and why should you care [online] available at: (accessed date 12/8/2018)


bottom of page