April 23, 2021

The Importance of Refactoring

In software development often things won’t get fixed until they are broken. In a lot of ways this is the natural occurrence of events – something breaks and someone comes to fix it. When a car suddenly refuses to move, you call a mechanic who can hopefully fix the problem right away. If it takes longer, it can become a very stressful situation, especially when you have an important appointment somewhere. This can throw you completely off the grid and cause an immense amount of trouble for you. When the mechanic is done, she might offer a word of advice to you: Get a regular check up of your car!  By doing this issues that might arise in the future can be anticipated before your car completely breaks down, saving you from stress and big financial problems. And, yes, we are now getting back to the real topic here, because in a very simple way what refactoring does is checking up old code and anticipating future trouble. 

Now code refactoring should not be confused with rewriting the code. When the code is rewritten the outcome is often changed to meet new requirements. Refactoring on the other side means updating or improving the structure of the code without actually changing the external behaviour. So in the short run the customer won’t care about refactoring since they won’t benefit from it. Long term there are a lot of benefits that come with the extra work of refactoring, so let’s jump right into them.

Refactoring keeps the code clean and up to date. What is meant by that? Well, in the refactoring process all the redundant lines are cut out, unnecessary loops are removed, classes that are too long are cut into smaller portions. Basically all the unnecessary code is eliminated. This makes the code cleaner and easier to understand and therefore easier to work with. So if a new feature is to be introduced, refactoring the old lines makes the installation process simpler.

Fixing bugs will also be simplified when the codebase is cleaned up. Just like in real life it’s easier to find where the ants are coming from when there isn’t junk lying around everywhere. Developers get a better overview of the systems and are quicker to understand in which segment the bug is located.  

Cleaning up the code will also improve the customer experience. Let’s go back to our imaginary car: If there are many parts in the car that don’t really fulfill a purpose and only add to the overall weight of the car, the speed will be limited. Throw all the unnecessary parts out and you will be amazed how fast the car can actually go. So if there are many complaints about your application being too slow, refactoring might do the trick. By  throwing off old useless lines of code the customer experience will improve significantly.

Every company’s goal is to find practices that can save them time and even more importantly: money. And that’s exactly what refactoring can do. First of all: by getting a clean and easily understandable code, the work of the future developers will be a lot less annoying. Instead of spending hours trying to figure out what the f*** happened here, they can start right away. This saves time, money and a ton of nerves of the developer. To understand another way in which refactoring can save money let’s go back to the car example. Getting a regular check up also costs money and time is needed for this as well, but it will ultimately be cheaper than crashing while driving. Or in other words, spending some time and money on refactoring will prevent the enormous costs that will arise if the entire application goes offline. 

However refactoring is not the silver bullet of software development. There are times when refactoring is not appropriate: For example when you are facing a tough time line, making sure everything works properly is more important than how the code looks. Also perfection is not the aim when refactoring. If you are not 100% satisfied with the refactoring work, you should remember that the code you just refactored will need to go through this exact process again in some time. It’s a bit like cleaning up the kitchen. Understand refactoring more as a maintenance process that needs to be done every couple of month 

Refactoring is a healthy habit that companies should adopt when they want to build a sustainable and lasting product for their customers. The question that remains for now: How do you know which files need refactoring the most? Well you’re already on the right page, with the insights from Jonny Git you know exactly which ones the critical files are.

E-mail us

Let us call you back

We are ready to help