Today, in this article I’m gonna talk about code quality something that we all care about quite a bit in our day-to-day development. But before dive into the steps of improving code quality. I wanna tell you about a story of when I asked the question on Code Quality to my fellow software developers. Almost every definition I get is not good except for the following one.
There no such thing as Code Quality.
Really this is not funny! Let’s see the real definition to improve the code quality.
The better the code quality the less we have to spend time to maintain it.
Let’s dive right in.
- Review my own code after complete
- Write clean code not clever
- For what purpose did you write a comment
- Code quality must inherent requirement for every development task
- Write better functions apply slap
- Give good meaningful names
1. Review My Own Code After Complete
I have this habit of after typing the last line of code. I review my code three or four times mentally. I always surprised at how many issues–I can find in my own code and they only become visible when I take a step back and review my own code in isolation.
The main point here is the: code quality starts with the code author. You shouldn’t rely on automated tasks, quality assurance or user acceptance testing to catch your mistake.
It might also save you from some embarrassment 😳. Also, there’s a great saying on reviewing the code.
A good code should read like a story, not like a puzzle.
2. Write Clean Code Not Clever Code
Writing coding is what we have all been doing since we start to learn to program. I’m assured that all of us write clever code that no one understands unless the author. So, the other developers mock you when they are trying to find what all is happening in your code. It’s never too late to take care of your code.
Here is the list of chracteristics of clean code.
- Let one function or method perform only one task.
- Make code more readable for people– Mostly code you write is not only belong to you. It belongs to your teamwork as well. So, it’s in your best interest to set your teammates up for success. Enable them to maintain your code.
- Contain no duplication.
- Run all test.
- Each function and class must not depend on so many dependencies.
A beautiful quote from Tony Hoare on clean code design:
There are two ways of constructing a software design. One way to make it so simple that there are obviously no deficiencies and the other to make it so complicated that there are no obvious deficiencies.
3. For what purpose did you write comment
We as programers comment the hack out of things. Sometimes we write more comments than the code. There are two types of comments we write in our day-to-day development.
- Comments that tell the reader what the code is doing is deserved.
- Don’t comment the code to cover up the bad code– Like when someone says I don’t understand this code, this is too much complicated. We like No! refactor the code that hard to understand not comment it.
So, the comments should tell us why the code exists, tell me the gist, what were you the reason or motivation to create this code, what’ll happen if someone doesn’t maintain certain conditions, preconditions, and postcondition.
Some people write comments is like they explaining a joke.
4. code quality must inherent requiremenT for every development task
The efficiency of code quality is important but laziness is harmful. Laziness creates a growing backlog of bad technical debt. We can’t be passive and maintain code quality. It requires time and efforts.
Project managers and product owners generally aren’t concerned about code quality –they have their own problems to tackle. Requesting extra time for code quality can make them so much horrible person. However, maintaining code quality shouldn’t be thought of as something extra — it should be an inherent requirement of every task.
5. Write Better Functions–Apply Slap
You’ve probably written hundreds of functions in your time as a software developer. But not functions are created equal. And bad functions directly affect the readability and maintainability of code. So what is a bad function and what makes a good fucntion?
Characteristics of a good function.
- It has a proper name.
- Returns a value.
- If possible make it pure.
- Has a single responsibility.
- Don’t has nested IF conditions.
6. Give good meaningful nameS
There are two stages for every programmer: I’m God and I have no idea what do I name that variable.
Seriously, if you did not write the meaningful names for variable, functions, and classes. The world will collapse, your company will run out of business. Just Kidding! The names should be descriptive enough that other people, and not just us, will be able to understand the purpose of the variable, function or method, and class.
Make sure your names are short and precise, but when in conflict favor precision. Strongly optimize around developer efficiency and make it easy to find files via “find by name” IDE shortcuts. Enforce good naming stringently with code reviews.
Last I just wanna say this, as a developer if we don’t change the way we think about code quality, we can’t expect someone else to.
If you found this article useful then please share the knowledge with the community. Also, if you’ve any more suggestions about improving the code quality. I’d love to hear your suggestions in the comments section. Don’t forget to hit the ♥️ like button.
Thank you for being here and keep reading…