Programmer Best Practices — Clean Code

Spread the love

To be a professional programmer, there’re many things that we’ve to do to be a good one.

In this article, we’ll look at the most basic requirement to be a good programmer, which is writing clean code.

Clean Code

Code is what we have to write to make things that businesses want.

Therefore, we’ll have to live with them for a long time.

This means that we’ve to write code that we can change and read easily.

Otherwise, we’re making our lives difficult.

Writing clean code is a way to make them clear and easy to change.

We just got to strive to write clean code.

Code is the way that we express requirements, so we should make them self explanatory so that we or other people can know what the code means.

Bad Code

Bad code is just code that we can’t live with.

Bad code includes code that has bad naming, messy logic, bad organization, and many more things that make reading and changing it difficult.

Bad code may be faster to make when we’re writing them, but we’ll pay dearly later.

This is because one will understand what we write when we go back to look at it.

Everything is so confusing that making even simple changes would be very difficult.

Therefore, we should always clean up our code after we got something working.

If we leave it, then it’ll haunt us later.

We should clean it up immediately. Otherwise, we’ll never clean it up.

Costs of Messy Code

Since changing bad code is so hard and time-consuming, it’ll definitely cost us more money.

Also, if we make changes, we may break other parts easily.

This isn’t good at all since we customers will notice if the bad parts are released.

Productivity decreases and customer complaints increase with bad code.

There’s just no way that bad code can be good for anyone.

The more change we make to bad code, the messier it gets, and productivity decreases more.


Eventually, the code is so messy that making changes is impossible and the code has to be rewritten from scratch.

This takes lots of time since we’ve to replicate all the parts of the existing software.

There are many cases and boundary conditions that we have to worry about.

We always encounter issues when writing code, especially if it’s such a big rewrite.

Therefore, it just takes longer to rewrite the code.

Something that takes minute would take hours, and something take hours would take days.

Changes to one module may lead to changes in 10 or more other modules.

It’s tough to rewrite code.

Therefore, we should always leave time for cleaning up our code from the get-go.

We should give ourselves generous estimates so that we can clean up after ourselves.

And then we won’t run into all the problems that we’ll encounter later on with bad code.

The business probably wants good code so that we can work on them faster.

Therefore, we should think about that when we make estimates.

Making messes to meet deadlines just isn’t a good idea.

The moment we finish writing the messy code, we’ll be confused by them immediately.

Meeting deadlines means that we should write our code cleanly.

Clean Code is an Art

Writing clean code is an art.

We’ve to use lots of little techniques in a disciplined manner to create clean code.

We’ve to acquire the sense of writing clean code.

There are many definitions of clean code. Some may say it’s elegant.

According to Mac’s built-in dictionary app, elegant means ‘pleasingly graceful and stylish in appearance or manner; pleasingly ingenious and simple.’

It’s supposed to be pleasing.

Clean code should be pleasing to read.

We shouldn’t be tempted to turn our code into a mess.

Error handling should be complete. Also, broken bits should be fided.

Clean code does one thing well.


The cost of messy code is just too high.

Therefore, we should write code that is clean and well organized, and easy to read and change.

Clean code makes us work faster and messy code will slow us down to a point where working with the code is almost impossible.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *