Clean Code — it's really Messy!

Bramantio Krisno Aji
3 min readMar 11, 2020

--

source: https://dribbble.com/shots/7022188-Cleaning-Code

what the hell is this?

Have you ever think like that when you see your legacy code? like you completely forgot and lose track on how what and why is the variable haha12345 exists in the first place. You forgot what is the purpose of the function ashiaap() you made.

The simplest explanation to this is that your old self didn’t apply the term Clean Code!

What is Clean Code?

like usual before we start let’s see the definition of “Clean Code” itself. Clean Code is a code that other people or simply your friends can easily understand, reuse, or refactor it. There is no clear goal on Clean Coding. Basically it is a code that is simple, understandable, bug-free and easily maintained by other people. There are a few characteristics for clean code to make you easier to get the point of the Clean Code.

Characteristic of Clean Code:

  • Clean code is an elegant code, An elegant code basically describes how the code look, performs and how it really encompasses and served well for the programmer to read. Programmers can spot on what variables and functions are for.
  • Clean code is more focused, which means each function, each class, and each module really meant for a single purpose. Such that it cannot be bothered, undistracted, unpolluted by any other running details.
  • Clean code can be easily maintained, well you can easily translate what this point means, right? 😋

Now, we know about Clean Code and its characteristics. But how can we apply it? let’s talk about it…

How to Write Clean Code?

There are several principles of clean code, below are several infamous principles:

  1. KISS (Keep It Simple Stupid), A design principle that meant to avoid unnecessary complexity. You have to ask yourself “Can I write this code in a more simple way?”
  2. DRY (Don’t Repeat Yourself), This design principle emphasizes that every piece of code must have a single, unambiguous representation within the code so that it there will be no repetition of the same block of code. You guys can practice this principle by study about “Advanced Programming”.
  3. YAGNI (You Aren’t Gonna Need It.) — This described that we only implement a function that we really need. If it is irrelevant we should delete it or replace it with another function.

To make it visible I have a little example from my project, it looks like this:

On the example above you can see I always make variable which can be easily understood to read. Just name it with the purpose of the variable itself, it really helps you to know the function of it, for now, tomorrow, or even in the future. Just like one quotes I found…

Master programmers think of systems as stories to be told rather than programs to be written. — Robert C Martin.

Okay guys, I think that’s all I can share with you about “Clean Code”. Don’t forget one thing “practice makes perfect!”.

Happy Coding… See yaa peace! ✌

References:

--

--