fbpx

What is a good code? Some say a good code has 100% test coverage while others say it’s superfast and has a killer performance and will run acceptably on 10-year-old hardware. However, there is no consensus yet on what a proper definition of good code is as it continues to evolve over time. But, the most important rule to remember is to keep your code clean and easy to read.

Use descriptive names
By using unclear and nondescript names for variables, classes, and functions you are making your code obscure to your fellow programmers and also to yourself. You would have to read the entire code to understand a simple variable which can be avoided by using descriptive names.

Give each class and function one purpose
Clean code is broken down into classes and functions which aim to do a single thing or represent a particular concept. As Jazzwant says, programming is all about breaking one big impossible task into several small possible tasks.

Delete unnecessary code
Every programmer struggles with unnecessary code. The problem occurs due to the accumulation of a whole lot of commented-out blocks of code that are no longer needed yet clutter up source files. To get rid of it, start using source control right away.

Enhance readability
Most programmers confuse a cleaner code to a compact one. Though it takes a little space, is it really clean and easy to read? Not always. Optimize your code so that it is easier for you and others to read.

Write good comments
A good comment explains why the code is existing rather than what is. Good code is self-explanatory. Hence, your comment should shed light on the intention behind why it was written.

There is no right way to write a clean code but there are many wrong ways. Be aware of them and keep your code clean and better.