WHAT IS A CLEAN CODE?

Akshat Uppal
3 min readMar 21, 2020

--

Clean code is code that is easy to understand and easy to change.

I am selecting this title as many people from the tech/ coding background are curious throughout their journey about Is my written code really clean?

Is this code clean? I Doubt.

People need to understand the code we write, we can say that the code we write is not intended only for the computer but also for humans.

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

Being a coder myself, I have asked this question to myself so many times. So let's face it today. Let's try to understand, what clean code actually is and know the status of what we have been writing since our college times. After going through the rules to write clean code, do comment on what’s ur code status till now?

Here are the tips which you need to follow in order to write a clean code.

  1. Nomenclature: One of the most important parts of our code is how we assign names to our variables. The biggest factor impacting the readability of our code is the way we give names to our variable. Always use meaningful, descriptive and pronounceable names for your variables so that code readability is not impacted.
  2. Functions: Firstly, functions should say what it does i.e nomenclature of the function is very important. Secondly, remember this as one of the most important tips/rules of software engineering, i.e. One function should do at most one task. Thirdly, Avoid passing more than two arguments in a function. That would make a function complex. It's harder to test/ debug complex functions though.
INTERESTING?

3. LOC (Lines of Code): Its a misconception in many software engineers that small code is more cleaner then long code. This is not always true. LOC doesn’t directly impact code cleanliness. Sometimes, a long code is more readable and understandable compared to the shortcode.

4. Comments: Many of us must have faced a situation where we read code of ourselves or someone else’s after a long time and we are not able to fetch what actually that code is trying to say. That is dues to two reasons:

a. The code nomenclature is very bad.

b. Absence of comments, where required.

Comments are very important to write, as it helps to get an understanding of what the code snippet is doing. But of course, we can reduce comment writing to an extent if we focus on nomenclature. As it will improvise readability and help to understand the code without comments.

Once you follow the above-mentioned practices, you will come one step ahead of writing clean code. It's not like you will be able to write a final clean code in one attempt. Its never-ending process, as you can refactor your code to an extent in multiple iterations and make your code more clean and readable.

In this post I have tried to explain what clean code means to me and also hopefully convinced you that you should also care about clean code practices (in case you didn’t previously).

Clean code always looks like it was written by someone who cares. There is nothing obvious you can do to make it better.
— Michael Feathers

--

--

Akshat Uppal

Python Developer and Machine Learning Intrigued person who loves to explore new things and writes to share my learnings with you.