System Init
0%
LOADING_ASSETSv2.0.26
blogs/refactoring-hidup--menerapkan-prinsip-dry--don-t-repeat-yourself
//Khay
Baca Bahasa Indonesia

Refactoring Life: Applying the DRY Principle

LifeProgrammingHabits

Yesterday I saw my roommate throwing a tantrum trying to find his motorcycle key for the 10th time this week. Even though last week he spent hours looking for it until he was late for class. Next week, I am sure he will be looking for that key again.

As someone who highly values efficiency, seeing something like that makes me feel extremely itchy. It is like seeing the exact same code repeated in various different files without ever being consolidated into one centralized function. In the world of software engineering, a disease like this violates the most sacred principle: DRY aka Don't Repeat Yourself.

The DRY concept is simple: every piece of knowledge or logic must have a single, unambiguous, authoritative representation within a system. If you need that logic somewhere else, call the function, do not copy-paste the code. Why? Because if the logic is flawed, you only need to fix it in one place. Imagine if you copy-pasted the code into 50 files, and then there is a bug. You would have to fix all 50 files one by one. Exhausting, right?

The problem is, many people do not realize that they are running their lives using the WET principle (Write Everything Twice) or rather "We Enjoy Typing". They do the same routine, make the same mistakes, complain about the same things, over and over again, without ever thinking about creating a system that can solve the problem permanently.

Back to my friend looking for his key. Instead of lamenting his fate every time the key goes missing, why does not he just refactor his habit?

The solution is incredibly easy: buy a 50-cent key hook at the store, nail it near the door. Create a rule in his brain: every time he enters the room, the key must be hung there. O(1) time complexity. No more needing an O(n) algorithm to search under the bed, inside shoes, or in yesterday's jacket pocket.

This is called automation. Automation does not mean you have to use robots or advanced AI. Automation is when you build a system once, and that system works to eliminate friction in the future.

I also apply this to other things. I used to get headaches choosing what clothes to wear to campus. It took up time and mental energy (decision fatigue). Eventually, I implemented a modular system: bought a bunch of plain black and grey t-shirts, two pairs of jeans, and one jacket. Done. I wrote an algorithm "take the topmost shirt in the closet" and run it every morning. My thinking time drastically decreased, and I could allocate my brain energy to think about more important things, like fixing bugs in my code or figuring out why girls suddenly get mad even when we did not do anything.

The same thing applies to romantic relationships. You date someone, fight because of poor communication, break up. You date a new person, fight using the same pattern, break up again. That is your code that is wrong, bro. You have not refactored the root cause, but you are already trying to deploy a new project using a different framework. No wonder it still errors out.

From now on, try auditing your life. Find the parts that you keep repeating that make you tired. Do you often forget to pay bills? Set up auto-debit. Do you often forget to drink water? Buy a large 2-liter bottle, put it next to your laptop. Are you tired of doing piled-up assignments at the last minute? Use time-blocking.

Do not be enslaved by your own bad routines. Build a system, automate habits, then relax in peace.

  • Khay