What is Clean code?
By: Dhananjay Trivedi
Tags: Coding, Programming, Computer Science, Software Engineering, Software Development

I was recently advised to read the holy bible of Software Engineering called Clean Code by Rober C Martin. Here I am sharing what I learned from the book. I would highly recommend you to read the book.

Me looking at my code, after reading Clean Code

There was a company that made a killer app that got pretty popular among a lot of users. After multiple releases/updates, the number of bugs increased and eventually people got frustrated enough to stop using it and eventually the company went out of business. When asked one of the engineers about what happened, he told

“ They had rushed the product to market and had made a huge mess in the code. As they added more and more features, the code got worse and worse until they simply could not manage it any longer”

So that is the power of bad code, it can bring your organization down. By the way, you (alright me!) have written bad code some times in our lives. What are some of the popular excuses for writing bad code?

Less time to do a good job, my boss would be angry if I would have taken more time to clean up my code.

Tired of working on the program and wanted to just get over with it and just into coding a more interesting module.

Just don’t feel like cleaning up the mess and push it for later some magical day.

After all, a working mess is better than nothing, right? We all have been there, we all have done that!

What does it cost to write Bad Code?

As the code-mess keeps on building up, it gets harder to maintain for developers and hence it keeps slowing down the developers. The more developers work on that mess, the slower they will get with time.

Seeing the decrease in productivity the management adds more resources to work on the mess, which eventually makes things worse.

In some cases the developers realize the mess they have made and inform the management about it requesting a redesign from scratch, the management has to bend down seeing the drastic decrease in productivity.

Now the organization has to create a new team to create a new system from scratch and while the other team still has to maintain the mess until the requirements are being satisfied by the new system.

After some time even the new team realizes that they have created a mess of their own while trying to catch up in the race. So a little bit of refactoring your code can save you and your Organization a lot of time, frustration and resources.

But whose fault is this?

The fault is not in our stars, it’s in us!

We write sloppy code, we make unprofessional promises to our managers and marketing people who look up to us to give them the required information to plan out things, to make commitments for the project.

We give them bad data, they come up with bad plans and we build a bad code base, things go bad and we end up blaming each other.

The client/user validates the system by the number of requirements full-filled. The managers look up to us to work out the plan and then walk on it as per the deadlines set.

Think of the client as a patient and you are the doctor. You as a doctor has to sterilize yourself and your tools before you operate which will take some extra time even though the patient is complaining about the time. You being a professional doctor have to defend your work because you know the importance of the way things are being done.

It would be being unprofessional on your hand as a developer to bend to all the wills of the manager who might not understand the risks of making a mess.

We make the mess to meet the deadlines, but the point to be noted is that once we make the mess it immediately starts to slow you down. In order to meet deadlines, always keep your code as clean as soon as possible.

But How? So try to understand that.

What is Clean Code?

We can never perfect our code. Nothing is perfect, there will always be flaws, but you being a professional developer can strive for making the code as clean as possible. But here are some quick points to help you understand what all factors are involved to make your code clean-code…