Clean your code!

Anastasia Audi
4 min readOct 26, 2022

--

I guess that many of you may have heard of clean code or code smell. Well, in order to produce high-quality code and maintain it ready for fast pace development and operations, applying clean code will definitely help you with that.

But what is the Clean Code?

https://techcastle.com/10-ways-to-clean-up-your-computer/

Clean code is easy to understand and modify by other programmers. Moreover, writing clean code is the best practice since we want it to be maintained efficiently.

Clean code is a clear, traceable, logical, and disciplined implementation of code in your program. Writing readable and reasonable code is a crucial skill every developer needs. If you have not implemented clean code as your software development practice, you might’ve noticed some problems with extensions or errors during adaptations. Clean code principle matters because it is a foundational skill that will benefit you when it’s time to refactor the code or test them.

Here is a list of things you can do to have a clean code:

1 — Have SOLID principles

Following the SOLID principles is an excellent way to ensure that your code is flexible, maintainable, and long-lasting. This principle is to help developers write clean, well-structured, and easily maintainable code. The SOLID guide consists of the following:

  1. Single responsibility principle (SRP)
  2. Open-closed principle (OCP)
  3. Liskov Substitution Principle (LSP)
  4. Interface Segregation Principle (ISP)
  5. Dependency inversion Principle (DIP)

You can find them through this source to learn further about the SOLID principles.

2 — Start writing less code

As you write your code, you often forget the number of lines you’ve written and whether or not it’s clear. Especially if you’re busy fixing bugs or adding features, you lose focus on how clean your code should be. Therefore, you should start taking care of your code and make it as efficient as possible. A good example is avoiding lots of nested loops. Not only that it is very hard to digest and very long, but it also produces a bad time performance. You can try to simplify the code by implementing algorithms or extracting them into separate methods.

3 — Implement good naming

You might’ve seen some poorly named variables, classes, and functions. By implementing good naming, you’re basically contributing to writing readable code and can easily understand what it does without having to add any unnecessary comments. This will also save time for the development team because they can easily comprehend the named variable’s function.

4 — Stop code repetition

There’s a principle in programming that says, “Don’t Repeat Yourself” or, in short, “DRY”.That principle means that we need to avoid writing the same code repeatedly. Reducing code repetition will make your whole code cleaner. Implementing DRY will reduce code redundancy and will enhance code readability. One implementation that we can do is to create a component in our flutter project. Using reusable components can help reduce code duplication and shorten the code.

5 — Rethink your comments

Whenever we finish writing our program, we comment on it to remember what the program does. Despite being helpful, sometimes those comments get too much and make our code looks terrible. That’s why we need to rethink again before commenting on our code. A good code should be able to speak for itself.

Clean Code Implementation

Implementing a clean code strategy has helped me to write better code as a front-end developer. Since we’re working collaboratively, it is necessary to understand each other’s code. A good example is grouping our files into a good system, and we use the proper naming system for our file names, variables, methods, classes, and functions. This definitely helped us understand each function in each other’s code.

Another thing, we also do not use any not necessary comments in our code because we’ve created a straightforward naming convention. This can minimize any code smells, especially for clarification comments, because it can indicate that the code is too complex.

To conclude…

I know that this article is far from complete, but I do encourage you guys to start caring about your code quality and implement clean code strategy to your future development projects. Please do seek further information regarding clean code, and thank you for reading this article!

References:

Your ultimate guide to clean code

10 Steps to clean code

--

--

Anastasia Audi

A Computer Science student who have huge interest in front-end product development and UI/UX Design!