Process, Web Development

5 Reasons you Should be Writing Clean Code

White Lion — February 24, 2016

What is Clean Code?

If you ask five developers what they consider to be “clean code,” you might get five different answers as each developer has their own style. If the answer is just “I use comments”…that’s WRONG! Clean code is reader-focused and consists of code commenting, for sure, but also includes the logic the developer uses to structure the overall code base. From their naming conventions to the structure of their classes and namespaces, clean code makes it easier to read, maintain, and build upon. Think of a project’s code base as a house and clean code is its foundation.

1. Writing is Easy, Reading is Hard

As developers who write all day, we tend to forget our code will be seen and worked on by others. This forgetfulness can lead to code that is incomprehensible; resulting in a whole mess of confusion. When writing code, it’s always best to have in mind the code is not just for the end product, but also for others to read and follow along with ease. This way of thinking can help prevent future contributors from wasting time trying to understand the code to fix any bugs, and instead focus on adding MORE features. Developers are authors and our code is the story. The cleaner the code, the better the story.

“Programming is the art of telling another human what one wants the computer to do.” – Donald Knuth

2. There is Method in Madness

Clean code is written not only for computer consumption, but also as a method to communicate our ideas to other humans (re: developers) clearly and cleanly. Sure a piece of code can be written neatly and function correctly, but the next step is to ensure the reader of the code understands it by explaining how it works. Helping a reader know exactly what is going on behind the scenes justifies a developer’s logic or their way of thinking. In most cases, if the logic is unclear, professional developers will prefer to rebuild the logic rather than attempting to follow along.

3. Modularity

In a world where technology advances on a daily basis, web development is no different. There are always new ideas and features to implement to make an innovative, complex end product. With clients hungry for these features, we as developers need to have a good foundation to build upon. With a good foundation and features, bug fixes can be implemented more quickly and efficiently while reducing the amount of change; keeping the same overall code structure, as well as removing any old or unneeded code. With the extra amount of time saved from not fixing bugs or trying to decipher messy code, we can focus on more testing and quality assurance. In the end, clean code will lead to a well constructed project and a happy customer.

4. Revisit and Refactor

Writing clean code does not always happen at first. As developers, it’s our job to always revisit the code and improve the clarity of our logic. It’s best to think there is always a better, more efficient way to do something. When we revisit our code, we can refactor and shorten our original logic thus making it more maintainable and extensible.

5. Cleaner Code = Happier Developers and Clients

Writing cleaner code not only helps the developer who originally wrote the code, but it is immensely important to other developers who work on it later down the line. Clean code is a major long term benefit to clients as well as their intended audience. How exactly does this benefit the client, you may ask, when they don’t even see the code, just the overall end product? As indirect as it may seem, cleaner code means “quality” code, and therefore a “quality” product. Customers who receive a quality product are almost always guaranteed to be a happy customer, and happy customers mean customer retention. More customers mean more business, and more business means more revenue. Revenue helps businesses grow; making employees much happier and that includes the source of clean code itself…developers. A happy developer leads to better products, meaning…cleaner code. The benefits goes full circle from there.

Subscribe to our email list

Get the latest news from the lion's den delivered to your email.