See all articles

Code refactoring for a cost-consuming project: Is it worth it?

In the first article of our “Sunk Cost” series, we discussed what are the biggest challenges when it comes to sunk costs in the field of software engineering. 

Be sure to read it if you want to get a general understanding of why the decision-makers even get in the sunk costs. 

But long story short, it’s not so much about not spending money on time-consuming tasks for your app. It’s about doing it in a smart way.

And refactoring your source code, might be a tough but unavoidable decision, if you want to ever see your project bring profit.

Having seen a couple of such cases with our clients, we at iRonin.IT know when and how to do it right. Over 20 years of experience has taught exactly what are the benefits of code refactorings and how to make sure to get it right. Especially in the situations when sunk costs have already incurred.

Stay with us and you’ll learn:

  • what is code refactoring?
  • does code refactoring interfere with the other app works in progress?
  • why it’s a good idea to choose code refactoring?
  • how to make sure your code refactoring goes smoothly?

Let’s go!

What exactly is the code refactoring process? What are benefits of refactoring?

Code refactoring technique is the process or method of restructuring existing code without changing its external behavior.

From the developer’s point of view the purpose of this process is to improve the readability, maintainability, and efficiency of the code.

But from a business standpoint, there are also quite a few benefits of refactoring:

  • Rewriting the code even by small steps can modernize it and ensure it stays up-to-date with current technologies. This in turn makes any potential future code changes go much more smoothly, even if it's handled by new development teams handle them;
  • Making code more efficient and maintainable
  • Future-proofing solutions and enabling fast implementation processes in the future;
  • Getting rid of security liabilities;
  • Reducing app downtimes;
  • Creating smart solutions to improve the design altogether;
  • Bug-free experience; getting rid of duplications and making clean code in general
  • Improvement of user experience, improving conversion rates, upselling, and cross-selling.

All mentioned perks improve the app’s performance significantly. This way, you attract new users and, more importantly, make them stay, as they’re not looking for an alternative solution to your competition.

From a marketing perspective, you meet the customer's needs and promise to make their problems disappear. From a broader business perspective, you are assured that the product has a future and does not make the same mistakes as before, which translates into more secure profit.

Win-win in every respect!

Can you perform code refactoring at the same time with new feature development?

Usually, it's not so simple to make the decision of rewriting the code. You may already have an active user-base that gives you feedback on features and demands the implementation code new ones.

Lucky, the answer to this headline's question is yes. However, you have to keep in mind that it will take longer, and you'll be stuck with a buggy codebase for quite some time.

There are also some project management tools and risks when refactoring your code.

  • It makes all estimations a new features more difficult (based on existing code)
    Redoing the old code influences almost all development processes. Therefore, it's not so simple anymore to estimate the timeline for actions & general milestones. The best practice here is to take from previous experiences. Let your teammates speak up about similar situations from their past.
  • It makes the performance unpredictable
    Even though the team is changing your app to perform better, it could be the other way around at first. It may not be a rule, but it's always better to be prepared for some negative performance feedback.
  • It makes resources management tricky
    Refactoring your code means new unplanned tasks. And this in turn causes interference with the previously scheduled work. Therefore, it requires some careful decision-making regarding the next course of action, but even that will not always cut it. Each task and ticket may need to be prioritized again.
  • It’s difficult for testing (at first)
    The code that needs refactoring is not the best written. And because it is not, so testing it both manually and automatically can be very difficult. The good news is that refactored code is much easier to test and to keep an error log for it. This makes such code much more readable, reliable and the diagnosis of potential errors much faster and simpler.
  • It may feel frustrating for both your team and users
    All aforementioned examples can cause some aversion among project participants. As some parts of an application work well and some not, the users might get frustrated about the product’s performance. On the other hand, the team has to crunch through the poorly written & unpredictable code. To top it all, they find themselves under the pressure of users and stakeholders, even though the app’s state is not at all their fault. Needless to say, such situation may cause a lot of frustration and employees rotation. This in turn slows down the whole process of refactoring, as new developers have to learn about the situation and the code again.
  • It may cause tension between development team and stakeholders
    Even though getting the sunk costs back is a common goal, the perspective varies for all participants. Software development is a complex endeavor on its own, even regardless of additional challenges. Stakeholders may not fully comprehend it with their focus on starting to make money again. This in turn causes some pressure on the development team to work faster. And as we know, faster almost never means better. Not to mention, possible, as some issues with the old code can get very critical, blocking the work on new tasks.
  • It may require to onboard only the senior-level team members
    Complexity of work requires having onboarded only senior-level team members that have all necessary skills that are required to assure delivery. Any member that is not representing this level is increasing delivery risks of the project significantly. It is mostly because they may have problems with predicting the behavior of the legacy code, which in turn jeopardizes both feature delivery timeline and introduces possibilities for bugs in the newly written feature.

To sum up: While simultaneous development and refactoring is possible, in some cases the refactoring process is so critical that it’s more than worth prioritizing, especially when it introduces huge project risks. You can read more about it in this article about migrating SaaS development to another team (IT project management aspect).

What is the purpose of refactoring and what problems does it solve?

Right, so we talked about all the risks. But there has to be some silver lining, doesn't it?

Is it possible for a company to spent money wisely on the code refactoring process?

What problems and needs does it actually address?

Although there's probably a million of those, let's focus on the most relevant to our topic.

Technical debt
Bugs, security concerns, poor technological decisions impairing app’s performance and speed of development

Technical debt means extra development work. It arises because of many issues: e.g.

  • when the previous team chose an ineffective architecture,
  • the selected solutions are outdated(e.g., support for a technology ran out),
  • processes to maintain code quality were not applied (e.g., testing/QA as part of the Definition of Done, if there was one at all),
  • lack of code reviews between team members.

This usually happens when deadlines are tight and software developers take shortcuts in the code to finish on time. It can also be that team members simply lack the proper experience or the processes know-how. 

In the long run, these shortcuts make further enhancements and maintenance of duplicate code more difficult, so in turn, they cost more. Luckily, refactoring your code counteracts just that. While it is a complex commitment, it ensures that you choose the best solutions and avoid many negative outcomes in the future.

  • Inability to pivot quickly to different niches
    When you realize you need to refactor your code, it is the first step in the right direction. But to truly get your investments back, you need to think even bigger than that. Modern economics teaches us that everything changes and the competition is tight. Refactoring gives the flexibility to quickly add new features and change existing ones. This in turn allows you to quickly address previously unaddressed customer needs (e.g. the ones of customers from the other niches).
  • Inability to develop and test new features quickly
    Refactoring your code may look like a big decision to make. But it might be the only one to save the whole project. The problem of poor quality legacy code is that it’s hard to add and test new functionality quickly. This makes it harder and harder to add new feats to address customer needs, thus losing momentum in the market and customer confidence.
  • Poor user experience caused by bugs and code-related issues
    Your app might be in the perfect niche and answer the most unanswered needs, but it won't bring you success if it's not user-friendly. Just think what influences your own decision-making when it comes to software solutions. It's not just about the pretty interface, but all experiences that come from using the app. No user will fall in love with the product that behaves in unexpected ways, loses data or gets randomly inaccessible after updates. Refactoring your code is the perfect time to once and for all get rid of all relevant bugs.
  • Lack of scalability - inability to handle many users at once
    Software scalability is a measure of how the performance of your software application scales as the load on it increases. This is one of the most desirable features of any modern app, although it is so often lacking. Luckily, if you have made decision on refactoring your code, you might as well work on its scalability. This is an important quality for any software system, allowing it to grow and change over time without needing to be completely rewritten. To some, it may seem that the scalability of the architecture depends solely on AWS or the other provider, and that it takes a few setting changes for the application to take the waves of traffic. Meanwhile, the problem is that unless the code itself was written with scalability in mind - you won't experience scalability even on a well-set infrastructure. 
  • Low availability - users’ issues with accessing the app
    Refactoring your code means you can update dependencies on a regular basis and easily introduce new features to the app. This in turn means that you can prevent most incompatibilities and extended downtimes. Be sure your team relies on development practices such as Continuous Integration/Continuous Deployment to help rolling out new changes and improvements. It's also a good opportunity to set up your infrastructure right to minimize other server-side issues and implement solutions like reverse-proxy for load balancing.

Security and legal compliance
Data security should never be undervalued. Be sure that developers take time to work on code security, so the data and codebase is protected from being lost, damaged or leaked. It's also a good time to define clear roles & permission levels for the users inside the app, if you haven't already. The last check should be whether your app adheres to GDPR (General Data Protection Regulation).

Code refactoring best practices: Conclusions

In conclusion, code refactoring can be a challenging and time-consuming process, but it is often a necessary step for modernizing and future-proofing software applications.

Code refactoring can provide numerous benefits, such as improving app performance, user experience, and security, as well as reducing downtimes and bugs.

Code refactoring can also present challenges, such as making resource management difficult, affecting the performance unpredictably, making testing difficult, and causing tension between development teams and stakeholders.

Despite these challenges, refactoring can be done alongside new feature development, but careful planning and prioritization are necessary to ensure a successful outcome. It is also important to have senior-level team members onboarded for the project to minimize risks and ensure successful delivery.

Be sure to read our next article, so it's easier to understand when it's not worth it to invest in code refactoring and how to make sure your software code doesn't need it in the first place.

Ready to tackle your technical debt with code refactoring? Talk with our team of experts. We understand that code refactoring can be a daunting task, but with our expertise, we can guide you through the process and ensure that your codebase is optimized for future development. Don't let technical debt hold your business back, reach out to us today and check with our experts. They’ll be happy to guide through the process in a way that matches your project’s needs.

Read Similar Articles