Clean Code Habit, Is It An Important Thing?

Isra Mela
IT Paragon
Published in
5 min readSep 13, 2020

Clean code always looks like it was written by someone who cares. ― Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship

A few years ago February 2018, I worked as a fresh graduate. As the first project, I created an android mobile application. I tried to open an android application that was developed during college to be modified and reused. And after trying to modify it for about one to two days, I finally chose to re-create the application. And well… I just realized that it was very difficult for myself to read the coding that I made about a year ago when I was in the third grade :)

Why did this happen? One of them is influenced by the mindset “The important thing is the program can run”. This was a classic poison that affected me during software development during my college days.

What is the clean code?

In my opinion, simply clean code is a method for writing a line of code to be neat, easy to read, understandable by anyone, and easy to customize by anyone if there will be change.

Why should care about Clean Code?

“Clean code is code that has been taken care of. Someone has taken the time to keep it simple and orderly. They have paid appropriate attention to details. They have cared.” But why should you care? What’s wrong with code that just works? — Robert C. Martin

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

People need to understand the code we write, we can say that the code that we write is not intended only for the computer but also for humans. There are many reasons, some of the most important reasons are:

  1. Clean code is readable and easy to understand — What happens if you are in one discussion in the room with people who speak a local language that you do not understand? surely you will be silent, do not understand the contents of the conversation especially if you want to join in to discuss. Yup…. that’s what it feels like if you have to continue to develop an application with messy code.
  2. More efficient maintenance — As any project grows, it will need new features or changes to existing features. Clean Code falls into the Quality criteria of the Quality Triangle, a variant of what is most commonly known as the Project Management Triangle.
  3. Feeling good — Have you ever felt insecure when sharing your code with others?… of course I have felt that way :) If you’re writing quality, clean code, you should feel super confident.

The clean Code can also be realized by a team that is open to receiving input and knowledge from anyone. It doesn’t always have to be done by a Technical Leader. So Code Review sessions have to be meaningful, not just Go Merge or No Go.

The principle is: first I am a developer, second I want to be a better developer, third I want to be a professional developer, not a smart developer.

Professional developers know that the way write code, they support clean code and high test coverage, mockup, and everything that will ensure their code will live forever.

How To Write Clean Code?

There are no hard and fast ground rules for understanding clean code, it all depends on which book or the reference you read. So herewith a few rules that I started trying to implement.

  1. Follow standard convention

Every programming language has its standard conventions, and usually, all programmers follow these standards to make their code easy to read by other programmers. For teamwork, it can be started from naming files, class objects, algorithms, solving logic functions, applying standard code styles, designing patterns, and most importantly consistency.

2. Function Rules

One of the important rules related to functions. I tried to keep them as short as possible. The explanation is pretty simple: a shorter function will do less (only one simple thing).

Second, a function should only do one thing. When I read a long function of my code, I realize that more than one thing is done there. For example in the same function open the DB connection, execute a query, convert the result to another type and handle special cases. Each of these things should be done in a separate place.

3. Comment

Usually, if I feel the need to write a comment, it’s because the code isn’t clear. There could be many reasons why the code is unclear. The problem with comments is that they are not always updated. Very often the code is changed but the old comments remain the same. We need to think of comments like documentation. It is an expensive artifact that needs to be maintained.

4. Unit Test

The main purpose unit test is to check that all the individual parts are working as intended. A unit is known as the smallest possible component of software that can be tested. Generally, it has a few inputs and a single output.

The workflow of unit testing in software testing usually follows this framework:

  • Create the test cases
  • Review or rework
  • Baseline
  • Execute test cases

5. Use Git for version history

Sometimes, features change, and methods need to be rewritten. Usually, we comment out the old code. But if you use the Git version control system, it will keep all versions stored, so there’s no need to keep dead code. Remove it and make code clean.

Conclusion

So, this clean code is a must! Because this clean code will greatly affect:
1. Our quality as a programmer
2. Software development in the future

Need a mindset and alignment of the visions of all parties involved, how to deliver high-quality software. Clean Code is only one small thing to make it happen.

Writing clean code is not a big or time-consuming task, but making it routine, and committing to it, will go a long way toward advancing your career and improving your time management.

The challenge is, the benefits of clean code do not feel instant, and cannot be seen from the outside. Users will not see the difference from the outside.

--

--