Untangling Legacy Spaghetti Code To Cook Up Microservices
August 12, 2024 Michel Mouchon
At this point in the history of programming, everyone pretty much knows what microservices are and everybody is more than acquainted with the legacy code – and often monolithic code – that has been created over decades by countless programmers who have evolved corporate applications to fit new conditions and new demands.
It is often called spaghetti code, and for good reason. The code is often a tangled mess of business logic and data – presumably the data is the meatballs and the user interface is the sauce in this metaphor. (It is important to not take a metaphor too literally, of course.) While ARCAD Observer can help IBM i developers figure out the architecture of these applications and ARCAD Transformer RPG can help convert older RPG applications to modern free form RPG – in this metaphor, these help you figure out what you are going to eat of the spaghetti code. But a new tool called ARCAD Transformer Microservices, ARCAD is now helping developers figure out where to bite first as they try to eat that plate of spaghetti code to change it into modern, modular microservices, one piece of spaghetti at a time without risk of splashing tomato sauce or meatballs on users’ white shirts.
ARCAD Transformer Microservices was introduced in early July, and it has some customers that are early adopters who have driven its creation but it is important to note that it is still in active development and ARCAD is still enthusiastically taking in feedback from customers to make the process of changing monolithic code into microservices easier and more efficient.
The tool can be used on RPG IV and later releases of the preferred programming language for OS/400 and IBM i platform, and RPG III programs originally written for IBM 38 systems can be mechanically ported to RPG IV and then have Transformer Microservices help developers change the business logic in the resulting RPG IV programs into modular chunks of code that can be individually maintained and reused in new applications. ARCAD Transformer Microservices generates free form RPG code. At the moment, Transformer Microservices is a plug in for the Rational Developer for IBM i (RDi) integrated development environment, but over time it will also be a VS Code extension, which is becoming more and more popular among the IBM i base.
The creation of ARCAD Transformer Microservices is a testament to the difficulty of trying to identify the correct level of granularity and encapsulation for business rules to create a Web service. If you make the encapsulation to coarse, you end up with smaller blocks of monolithic code, but it is still fairly big chunks that have to maintained and enhanced as a whole. At too small of a granularity, there will be too many microservices that comprise the application and this could create a different kind of complexity that is time consuming and costly to maintain.
The trick with converting legacy monolithic RPG code into microservices is to get the balance just right, and that is what Transformer Microservices is all about. It includes:
- Module selection guidance: RPG code highlighting for module extraction, aiding developer in selecting web service candidates
- Verification of coupling: Automatic identification of ”entangled code” to ensure the consistency of the extracted modules
- Creation of parameters: “Interface” Variables are transformed into parameters to simplify tightly coupled code
- Code audit: The developer is notified of any anomalies and assisted in adding any additional code that needs to be included
- Simulation and Code explain: the developer retains control over the transformation, without locking the code during audit and analysis activities
- Automated module extraction: A new procedure is automatically generated based on selected lines
- Code replacement automation: Replacement of the previous block of code with a call to the new procedure
- Duplicate logic detection: Any duplicate functionality is automatically identified and refactored into a single reusable procedure, improving code quality and avoiding repeat maintenance.
The goal of Transformer Microservices is to isolate business rules and business logic embedded in RPG applications and extract them from the legacy code to create a service program that could be used as a Web service. But it is more than that. Because RPG applications are maintained by the ARCAD software change management system, Transformer Microservices can reach into the existing code and replace that chunk of legacy code with a call of this service program. It sounds easier than it is, and in many cases, doing such an analysis to figure out where to extract the business logic to create the service program and resolving dependencies and redundancies in the application code is quite complex. Figuring out where to start chewing on the monolithic legacy code and working out all of the variables and dependencies is one chunk might take the better part of a day, but with Transformer Microservices, which has a broad and deep view of the application and its data structures and databases, this might only take minutes. And so, Transformer Microservices can radically speed up the time it might take to refactor applications to be more modern and more maintainable.
Transformer Microservices does not employ any kind of generative AI to make its recommendations or to make changes to spaghetti code – it is a strictly deterministic set of algorithms that has repeatable and auditable results, which should be a great comfort to the managers and developers at the IBM i shops that deploy it. That is not to say that ARCAD may not at some future point weave in some generative AI capabilities into ARCAD Transformer Microservices (as for some other products in the range, such as the application discovery module, ARCAD Discover, which is already AI-powered). So far in ARCAD Transformer Microservices, generative AI has not been necessary, as this part of the modernization process requires a result with 100% predictability.
In some cases, legacy code is so intertwined and complex that refactoring it and modularizing it is very difficult, with interdependencies being so numerous that a human programmer cannot keep track of them all. (There are reasons why applications become spaghetti code and there are other reasons – inertia, cost, time, and so on – why they persist). This is true of companies that have hundreds of thousands of lines of code as well as those who have tens of millions of lines of code. For those who are only managing tens of thousands of lines of code, their applications are relatively small and are very likely already more modular.
But for everyone else, Transformer Microservices provides many things as companies refactor their code: Speed and agility, but as well, the security and quality of the result.
The solution bets on the value of the existing code assets to provide modern and secured digital applications.
Michel Mouchon is chief technology officer at ARCAD Software.
This content is sponsored by ARCAD Software.
RELATED STORIES
DevOps Means Using The Tools You Already Have Better
Hybrid Release Management Means Creating An Application Schema
Take A Progressive Approach To DevOps
The First Step In DevOps Is Not Tools, But Culture Change
VS Code Is The Full Stack IDE For IBM i
Realizing The Promise Of Cross Platform Development With VS Code
If You Aren’t Automating Testing, You Aren’t Doing DevSecOps
The Lucky Seven Tips Of IBM i DevSecOps
Git Is A Whole Lot More Than A Code Repository
Learning To Drive Fast On The DevOps Roadmap
Expanding Fields Is A Bigger Pain In The Neck Than You Think
Value Stream Management: Bringing Lean Manufacturing Techniques To IBM i Development
Unit Testing Automation Hits Shift Left Instead of Ctrl-Alt-Delete Cash
It’s Time For An Application Healthcheck
The New Economy Presents New Opportunities For IBM i
Creating Web Services APIs Can Be Easy On IBM i
Jenkins Gets Closer IBM i Hooks, Courtesy Of ARCAD
DevOps Transformation: Engage Your IBM i Team
The All-Knowing, Benevolent Dictator Of Code
Software Change Management Has To Change With The DevOps Times
Attention Synon Users: You Can Automate Your Move To RPG Free Form And DevOps
Git Started With GitHub And ARCAD On IBM i
One Repository To Rule The Source – And Object – Code
Data Needs To Be Anonymized For Dev And Test
spaghetti is in the software architecture.
you can still “spaghetti” microservices, in the way you create the graph of dependency between them to produce a complex emergent behaviour. And if done, it’s not pretty, especially if distributed ; )