Brifing

Software Archaeology: Restoring Legacy Code with Generative AI

How to use Generative AI to restore legacy code?

Martin Fowler2 min

1The Tourist Trap

Legacy code repositories, especially those from the early 2000s, are often incompatible with modern systems. While Generative AI seems like a solution to understand and run this code, starting with a tourist approach can be misleading. This approach ignores the true state of the code.

2Misleading Optimism

Generative AI often adopts an optimistic attitude when trying to modernize code. For example, when adapting an old Java project to a modern Gradle structure, it may suggest dependencies that don't actually exist. This can prevent the code from running.

3Structural Misconceptions

AI may assume a standard Maven structure, ignoring older structures like Ant. This makes it difficult to understand the actual structure of the code and leads to misguidance. Such assumptions are particularly dangerous in legacy projects.

4Hiding Fundamental Issues

Example code generated by AI can hide fundamental issues. For instance, using a non-thread-safe class makes it harder to understand how the code actually works. This complicates the restoration process further.

5The Archaeologist Approach

Instead of the tourist approach, it's necessary to act like an archaeologist. This means understanding the true state of the code and planning the restoration process accordingly. Using AI with a critical eye is an important step in this process.

6Forensic Code Audit

Forensic Code Audit analyzes the history, structure, and health of the code. This includes evaluating which Java version the code was written in, its architectural integrity, and error management. This analysis shapes restoration decisions.

7Carbon Dating

Determining the history of the code is the first step in the restoration process. This is necessary to understand which technologies the code was written with and which era it belongs to. For example, the use of Ant indicates the project predates 2010.

8Architectural Integrity

The architectural integrity of the code is a critical factor in the restoration process. The 'Big Ball of Mud' structure, common in legacy projects, may require the code to be rewritten. This makes the code more modular and sustainable.

9Data Flow Analysis

Data flow analysis is important to understand how the code works. 'Stringly-typed' data structures, common in legacy projects, may require the code to be rewritten. This provides a safer and more consistent code structure.

10Safety Check

Error management and thread safety are important considerations in restoring legacy code. For example, swallowed exceptions or non-thread-safe classes may require the code to be rewritten. This ensures a more reliable system.

11Risk Assessment

Based on the Forensic Code Audit, it is decided whether the code needs to be restored or rewritten. This is a critical step for the future of the project. AI plays an important role in this process.

12Conclusion and Recommendations

Generative AI can be a powerful tool for restoring legacy code, but it must be used correctly. Instead of the tourist approach, the archaeologist approach should be adopted, and the true state of the code should be understood. This ensures a more robust and sustainable system.

Original article: Martin Fowler — Yazılım Arkeolojisi: Generative AI ile Eski Kodları Restore Etmek