Let’s Code, Clean

Ansif Muhammed
3 min readSep 15, 2021

--

“Code is like humor. When you have to explain it, it’s bad.” — Cory House

Why do you need clean code? The difference between a clean and dirty code is like life and death. A clean code is easy to understand and scale, so it will be easily used, modified and scaled ; it grows, remains live. Whereas a dirty code is difficult to understand, modify and debug, no matter how good the code be, sooner or later it will become obsolete ; a slow death. If you want your code to live, it’s important to write a clean code.

The scenario is like organizing your wardrobe, if you are organized you know where to look for what. If you are not, you will have to deal with the mess each time you need something from it. Now imagine if its not your wardrobe !!!. Same could be the situation of a co-worker or another developer who might have to work on your code.

Clean code can be read and enhanced by a developer other than its original author ~ “Big” Dave Thomas

Whats a clean code? A clean code is easy to understand. That’s your talisman, ask yourself if a total stranger can understand your code.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler

How to write a clean code? There are some tips, let’s go one by one.

I will try my best to keep it as simple as possible, so that we could put them to practice right away.

Name them right

One must be able to understand the purpose by reading its name.

Variables : Must have what is contains as its name, in its right casing [ snake_case (python)] . E.g. client_id instead of just id or client or ClientId. In case of a Boolean, it should be what it validates. age_above_12

Function : What it does E.g. userValidation [ camelCase ( java, javascript)]

Class :What object gets created from it. E.g. UserRepository [PascalCase ( Python,Java, JavaScript)]

One function does one thing.

Keep your code modularity, makes your code more readable and interpretable.

Horizontal and Vertical Formatting

Your code should not be too long neither vertically nor horizontally. It must be readable like an essay or a story.

Instead of a too long single page, split them to multiple pages.

Instead of having a long line that you need to scroll to understand, try splitting them to multiple lines.

Similarly with the code comments, it enhances the readability and helps others understand your code better; but take care not to over do it !

Small changes can make big difference in your code.

Let’s take small, easy steps towards clean code.

More to follow…

--

--