Achieve High-Quality, Fast-Paced Development with Clean Code

Gita Permatasari Sujatmiko
5 min readApr 11, 2022

--

Image source: Unsplash

This article talks about how we can achieve high-quality programming that is effective, efficient, and maintainable for fast-paced software development.

What is Clean Code?

Clean code is a reader-focused development style that produces software that’s easy to write, read, and maintain. It is about recognizing that our audience is real-live humans, not just computers. If our code is clean, it will be understandable by the team, without much explanation. With understandability comes readability, changeability, extensibility, and maintainability.

“Programs must be written for people to read, and only incidentally for machines to execute.” ― MIT professor Harold Abelson

But, it turns out that clean code is not just about easiness to read. It’s also important that the code is easy to modify, stable, and reliable. With clean code, we can achieve a fast-paced software development with high-quality code.

How to Clean Code?

  1. Follow standard conventions: When developing our software, we want the code to be beautiful, clean, and consistent. If the code rules keep changing, you (or your teammates) might get frustrated and not be able to read and understand the code.
  2. Say what you mean: You’re not the only one that will be reading and trying to understand the code. In the next few days, you might as well forget about what you wrote. Use comments as clarification of code but don’t use them to add obvious noise.
  3. Keep it simple and be consistent: Reduce complexity as much as possible and if you do something a certain way, do all similar things in the same way.
  4. Encapsulation & modularization: Encapsulate boundary conditions. Put the processing for them in one place to make your code more reusable. Break long programs into different files so that your code is more modular and digestible.
  5. Keep it functional: Functions are more understandable, readable, and maintainable if they do one thing only. If there’s a bug when writing short functions, it is usually easier to find the source of that bug. Functions should be small, do one thing, and have no side effects.

Benefits of Clean Code

These are the benefits of implementing clean code in our software:

  1. Easier to maintain: Writing clean code is about reducing technical debts. With lower technical debts, you’ll increase the quality of your work, the code will be much easier to maintain, and you can… save costs! Because maintenance can be costly. 💸
  2. Easier to test: It’s hard to test dirty code. Say you failed a test and you want to diagnose it, you don’t want to see a bunch of spaghetti code, right? 🍝
  3. Bugs are obvious: With clean code comes readability and clarity — it is obvious that bugs are also more likely easy to spot in a more to-the-point code.
  4. Simplicity: KISS (Keep it simple, stupid) is one of the general rules of clean code (by Robert C. Martin). Less is more. 🍂
  5. Consistency: Following standard conventions and doing similar things in the same way, create consistency. 😎

And all of those benefits lead to… faster development! 🚀

Code Formatting and Quality Tools

To keep your code consistent and 🌸 beautiful 🌸 while developing your software with your team, you can set a standard by implementing some tools. In this article, I’m going to give examples from my experience in the Software Projects course (PPL) in college.

Because my team is using Next.js to develop our frontend, we use ESLint, Prettier, and Husky to set standard style rules for our code.

ESLint is automatically comes installed and pre-configured with Next.js projects. ESLint is used for best practices on coding standards in JavaScript. Here’s the .eslintrc.json file that my team has configured.

ESLint configuration example

Next is Prettier. Prettier is used for automatic formatting of our code files. Here’s the .prettierrc.json file that we configured to develop our software.

Prettier configuration example

Finally, we use Husky for Git Hooks. Husky is a tool for running scripts at different stages of the Git process, for example, add, commit, push, etc. We would like to be able to set certain conditions and only allow things like commit and push to succeed if our code meets those conditions, presuming that it indicates our project is of acceptable quality. Here’s the .husky/pre-commit file that my team has configured.

The package.json file consists of this:

For things like code smells, duplications, vulnerabilities, etc, we use SonarQube. We use it to check our code quality.

Say there’s a code smell in our code, SonarQube will directly tell us the exact location of the smell.

With that, we can easily remove the smell. For example, this:

For further information about code refactoring, consider reading my next article. :D

These tools and configurations allow us to maintain our code to always be clean and beautiful and therefore faster development. 🌻🚀

--

--