Make the codes look amazing using AHA principle.

--

AHA is an abbreviation of “Avoid Hasty Abstractions” conceived by Kent C. Dodds. And it is about making the large abstraction into small parts. Therefore, the code is more straightforward to understand by other software developers.

Let’s see an analogy using AHA Principle.

Here’s Adam, a software developer of XYZ Business Inc.

His task is to make a function with validation for creating a user.

So, he codes like this.

Not Using AHA Principle

As a result, createNewUser() is a vast method because it has many codes, And there’s numerous validation that happens. Consequently, If there are upcoming more codes, Regarding future maintenance, this code could cause a dilemma.

Suddenly, Adam realizes the risk. So, he followed the AHA programming principle then started to refactor his implementation.

Now, His code looks like this.

Using AHA Principle

From the looks of it, the code is clear to follow, and if there’s an issue that occurs, It is peacefully to debug. Also, it is simple to update and append new logic.

Overall, AHA Principle is similar to the Single Responsibility Principle. It aims that the functions have one responsibility, And the main idea is to avoid large abstraction. So that, In the end, the codebase looks elegant and comfortable to maintain.

Author: Marc Kenneth Lomio | Full Stack Software Engineer | BlastAsia, Inc.

References:

https://medium.com/nerd-for-tech/dry-wet-or-aha-7c2132aaf047

https://kentcdodds.com/blog/aha-programming

https://dev.to/andreacanton/aha-programming-vs-single-responsibility-principle-4go

https://stephencharlesweiss.com/aha-avoid-hasty-abstraction

--

--

Marc Kenneth Lomio & Melrose Mejidana

Software engineers that shares knowledge and experience through this medium.