Clean your code, not your laptop

A person cleaning a Laptop. Is this clean code?

Well, if you’ve already done a software project with your friend, you should already know how clean code helps your project. Here, I will give you some tips so you can write clean and better code than you’ve previously written!

Benefits of Clean Code

Have you ever written a code, then one week later your app has a bug in the code you wrote before? If you don’t write a clean code, say you write the variable with non-meaningful name (like x, y, a, b, etc.). When you try to debug your code, you need to remember what those variables represent. But you represent the variable with no meaning at all, so you need to trace how your code run. Here, I will give you an example on my IT project on the Input Validation.

enum EmailValidationError { invalid }class Form1 extends FormzInput<String, Form1ValidationError> {
const Form1.pure() : super.pure('');
const Form1.dirty([String value = '']) : super.dirty(value);

static final String _form1RegexString =

static final RegExp _form1Regex = RegExp(_form1RegexString);

Form1ValidationError? validator(String? value) {
return _form1Regex.hasMatch(value!) ? null : Form1ValidationError.invalid;

In the code above, you can see that I am trying to create a Class for an input. If you understand regex, you should see that the Form1 class is a validator for Email. But, I just use Form1 for Email, Form2 for username, etc. This is a bad example. So, the name of the class, the variables, should have meaningful names. For the code above, Form1 should be renamed EmailInput or something similar. Here is the cleaned version of code:

enum EmailValidationError { invalid }

class Email extends FormzInput<String, EmailValidationError> {
const Email.pure() : super.pure('');
const Email.dirty([String value = '']) : super.dirty(value);

static final String _emailRegexString =

static final RegExp _emailRegex = RegExp(_emailRegexString);

EmailValidationError? validator(String? value) {
return _emailRegex.hasMatch(value!) ? null : EmailValidationError.invalid;

Okay now you know about the benefits of clean code. But how can you write a clean code?

I will give you 5 most basic principle in clean code.

  1. Use meaningful names
    Here, you should understand this step by the example I’ve given you. Just give your variable name a meaningful one, it’s not that hard. Don’t use x or y in naming any variable, please.

There are many benefits when all your team implements clean code, such as having easy readable code than when a problem occurs, your team can fix easily. Also your team can create tests easily, because they know what this variables is, what this method is, etc. Also, when you ask about your code in forum such as StackOverflow, if your code is so dirty, people trying to help you won’t understand your code, hence no one answered.


A Computer Science Student at Universitas Indonesia