Legacy Modernization with LLMs and the decisions nobody asked about
We asked the same LLM to translate the same RPG applications three times, and we got three different results. In most cases, the generated applications behave the same way, while not looking the same. The same program can be translated once into 14,500 lines of Java, another time into 26,300. Sometimes they also behave differently, but this is a problem we are putting aside here. How the code looks is what we are interested in.
LLMs can translate code. But how do they do it? A translation involves a lot of design decisions, big and small. The fundamental points are two:
- The LLM makes many design decisions, and we may disagree with them
- When asked again, the LLMs can make different design decisions
Why does this matter? After all, provided the code behaves identically to the original, who cares?
The people that would need to maintain the codebase for the next 15 to 20 years may care.
When we migrate, we have software that does something useful, like an ERP that lets us check what is in the warehouse and send orders based on that. We want it to keep doing exactly that, in another technology, typically because it is hard to find people who know the old one, or because we pay for hardware and software we would rather not pay for. The goal sounds simple: same behavior, from RPG to Java (or from SAS to Python, or from COBOL to C#). But there are many ways to do it correctly. Many different Java programs behave like the RPG original, and they can be more or less concise, idiomatic, fast, or maintainable. These factors will fit more or less well the needs of the organization. We should therefore consider not only the impact on the migration process but on the life of the system after the migration, and this depends on the design decisions taken during the migration.
The questions we want to answer
So the questions this article tries to answer are:
If we translate the same code multiple times, do we get the same result?
And where the results vary, on which decision points do they?
To answer these questions, we devised three experiments presented in article 1. We gave the LLM the same job more than once and left it free to decide how to do it:
- Experiment 1: the same programs, three times. Five programs from a large application, translated three times, each run independent of the others.
- Experiment 2: the same application, three times. A whole small application, translated three times.
- Experiment 3: one large application, once. More than half a million lines of code, translated entirely, to see whether similar programs inside it come out in the same way.
This series
- Article 1: the experiments, the costs, and the answers in short
- Article 2 (this one): what changes when we translate the same code three times, and the decisions behind it
- Article 3: whether the translations behave like the original
- Article 4: whether a large translation is consistent with itself
- Article 5: how I would approach a migration now
If we translate it three times, do we get the same thing?
Before we start: the experiments and their labels
- 1A, 1B and 1C are the three translations of five selected programs from LARGE, with access to all of LARGE’s source.
- 2A, 2B and 2C are the three translations of all of SMALL.
- LARGE was translated once, in separate sessions following a dependency plan produced by Strumenta’s tooling.
All runs used Claude Code with Opus 5.5. Our prompt said “Organize the project as you see fit”, and the agent ran headless: it could not stop to ask a client. We had no running IBM i, so when I say that a run agrees with the RPG, that comes from analysing the source, not from running the original.
Names are masked with asterisks or replaced by neutral names like Row, FIELD, and ChildProgram. You know, privacy and all. The code shown is excerpted; ... means omitted code or declarations joined from different locations.
Short answer: (mostly) the same behavior, but with very different code.
On the same inputs, the translations mostly produce the same data and the same reports. Not always: we found some bugs and some differences in behavior, and we will get to them. But they are the exception.
The code is a different story. To say something more scientific than “it looks different”, we measured how similar the translations of SMALL are, program by program.
SMALL, median similarity across corresponding program classes
| Measure | 2A / 2B | 2A / 2C | 2B / 2C | Unrelated programs |
|---|---|---|---|---|
| Java tokens | 0.39 | 0.36 | 0.49 | 0.18 |
| File-operation sequence | 0.95 | 0.92 | 1.00 | 0.03 |
| Referenced DDS fields | 0.97 | 0.97 | 1.00 | 0.02 |
The token measure compares Java after removing comments, package and import statements, and annotations, and normalizing identifier spelling. The file-operation measure extracts reads, lookups and writes in source order, independent of whether they are written as chain(file, ...) or file.chain(...). Field overlap compares the sets of source fields referenced. Unrelated programs of similar size provide a baseline.
I find the file-operation comparison more useful than a whole-file diff here. But it still has limits: an implicit read loop disappears from the extracted sequence, and moving a method changes source order without changing execution. None of these measures checks the result of a calculation.
The numbers say it clearly: the translations read and write the same files in the same order, using the same fields, but less than half of their Java is the same. Here is a summary of the differences:
Implementation choices that differed across the three translations of SMALL
| Area | 2A | 2B | 2C |
|---|---|---|---|
| File definitions | DDS parsed at runtime; generic records | Generated Java records and catalog | Generated record formats and schema metadata |
| Field representation | Shared pool accessed through string keys | Typed members such as int, BigDecimal, and String | Shared FieldPool with NumField and CharField objects |
| File processing | Base-class operations and support for an implicit primary-file cycle | DbFile<T>, a record buffer, and explicit Java loops | DiskFile, record-format wrappers, and explicit Java loops |
| Program calls | String registry and Ref arguments | Direct static calls for known programs; registry for dynamic or external calls | String registry and factories, with Field arguments |
| Program instances | Activation handling in the shared runtime | Cached activations | A new program instance for each call |
| Data-area storage | Properties file | Separate text file per data area | Separate text file per data area |
| Command-line form | --data DIR ... run ******** |
--data=DIR ******** |
--data DIR ******** |
Experiment 1 adds a few more: entry methods, transactions and negative numbers.
Where the translations part ways
Let’s open the code, one decision at a time.
Folders and packages
The directory trees already tell us what kind of application each run is constructing. These are selected portions of SMALL’s trees.
2A. Keeps CL programs separate and splits the runtime into database, job and RPG packages.
src/main/java/
└── ********/
├── cl/
├── programs/
│ └── ********.java
├── runtime/
│ ├── db/
│ │ └── DdsRepository.java
│ ├── job/
│ └── rpg/
└── stubs/
2B. Adds generated record classes under db/record.
src/main/java/
└── com/
└── ********/
└── ********/
├── programs/
│ └── ********.java
├── db/
│ └── record/
│ └── ********.java
└── runtime/
2C. Adds record formats under db/fmt and field objects in the runtime.
src/main/java/
└── com/
└── ********/
└── ********/
├── programs/
│ └── ********.java
├── db/
│ └── fmt/
│ └── ********.java
└── runtime/
├── NumField.java
└── CharField.java
The RPG cannot tell us whether a Java folder should be named record or fmt. That part depends on the conventions of the team that will own the code. The larger difference is that the folders contain different machinery. To see that, we have to open the files.
When to interpret a file definition
SMALL has DDS definitions that describe records and fields. Do we interpret them while the application runs, or generate Java from them beforehand? Here the examples in 2B and 2C describe the same source file.
2A. Reads the DDS source and parses it when resolving a file definition.
List<String> src = readSource(n);
if (src == null)
throw new RpgRuntimeException("CPF4101", "File " + n + " not found");
f = new Parser(n, src).parse();
2B. Registers a generated record class and its metadata in a catalog.
public static final RecordFormat FORMAT =
new RecordFormat("FORMAT", Row::new,
FieldDef.num("NUMBER", 6, 0),
FieldDef.chr("TEXT", 4));
...
c.physical("FILE", Row.FORMAT);
2C. Emits a compact schema description.
pf("FILE", "FORMAT", "NUMBER P 6 0;TEXT A 4", "");
In 2A, DDS parsing remains part of the deployed application. In 2B and 2C, generation has already happened. Both describe the same fields. When to read the DDS is our choice, not RPG’s. A client may want definitions that can be supplied at runtime, or Java classes that developers can open and navigate. Nobody asked.
What a field should be
An assignment that looks trivial in RPG can become a string lookup, a Java assignment, or a call on a field object. The declarations show what is behind that difference.
2A. Stores values in named slots and normalizes through the field definition on assignment.
private final Map<String, Slot> slots = new HashMap<>();
...
public void set(String name, Object v) {
Slot s = slot(name);
s.value = s.def.normalize(v);
}
2B. Uses ordinary Java members for these numeric and character fields.
public int number = 0;
public String text = "";
2C. Uses field objects carrying the width and decimal information.
public final NumField number;
public final CharField text;
...
number = num("NUMBER", 6, 0);
text = chr("TEXT", 4);
With an ordinary int or String, some RPG rules have to be applied elsewhere. In 2B, record values are normalized on write or update, while program variables can be Java locals. In 2A and 2C, assignments go through runtime objects. Those objects still implement different rules: 2A rejects an EVAL result too large for its field, while 2C silently drops high-order digits.
That is the source of the overflow example described in article 3: an error in 2A, 7325.33 in 2B, and 658.67 in 2C. According to the RPG, 2A is right to stop. The input fields are all valid; it is the intermediate total that overflows. So choosing a field wrapper does not automatically give us the right behavior.
There are successful details too. In a division-and-remainder calculation, all runs preserve the truncation of a remainder into a field without decimals before testing it. They also reproduce the specified rounding of the final result. So I would not describe one implementation as simply understanding RPG and another as not understanding it.
The decision for the client is partly about maintenance: ordinary Java types, or types that make the original field rules visible? The required arithmetic rules themselves come from the source. BigDecimal alone does not specify field width, overflow, or when to round; a fixed-length string needs padding and truncation rules somewhere too.
A second example makes the consequence of this decision even easier to see. One program counts the open orders for an item and stores the count in a field of three digits, and this is how the three runs declared it:
// 2A: three digits, and going over them is an error
dclN("COUNT", 3, 0);
// 2B: a Java long
long count = job.rows("FILE_A", RecordA.class).stream()
.filter(...)
.count();
// 2C: three digits, and the digit in excess is dropped
private final NumField count = new NumField(3, 0);
With 999 orders, the three programs do the same thing. With 1,000 orders, 2A stops with an overflow error, 2B writes a supply row with quantity 1000, and in 2C the count silently becomes 0 and no row is written at all. The rest of the three classes is equivalent, with the same query and the same branch, so the whole difference in behavior descends from the type chosen for one variable. The same happens in a program that calculates run hours from a quantity, passing through an intermediate field of four digits: with a quantity of 40,000 the first translation stops with an overflow error, the second gives 66.73 hours and the third 0.07.
Where the record cycle lives
Here is the same business program in SMALL, shortened to a lookup, an assignment and an update. This is a particularly visible difference if the people maintaining the Java used to read RPG.
2A. Marks a primary file and supplies a detail() callback; the base runtime drives the record cycle.
protected void declareFiles() {
file = file("FILE").update().primary();
...
}
protected void detail() {
chain(lookup, v("KEY_A"), v("KEY_B"));
if (!found(lookup)) {
set("FIELD", 8);
...
update(file);
}
...
}
2B. Writes the loop in the program and accesses the record buffer exposed by DbFile.
Row record = file.rec;
while (file.read()) {
lookup.chain(record.keyA, record.keyB);
if (!lookup.found()) {
record.field = 8;
...
file.update();
}
...
}
2C. Also writes the loop in the program, using DiskFile and field objects.
while (file.read()) {
lookup.chain(record.keyA, record.keyB);
if (!lookup.found()) {
record.field.set(8);
...
file.update();
}
...
}
SMALL’s primary-file programs use no level indicators and no explicit last-record termination, so an explicit read loop is enough for them. This is a choice about where the mechanism lives: inside a common base class, or visible in each program. The former resembles the source more closely; the latter gives a Java reader the loop in front of them.
What a failed lookup leaves behind
Some details of file processing do change results. Among the 14 largest programs, we found two defects in 2B on ordinary, non-edge paths. They show why the record layer is more than a convenience API.
- Position after a failed CHAIN: a later READ in 2B can restart from the first record because its position is null. In the reviewed program, this repeats processing and writes. 2A and 2C instead reach end of file, as the RPG does.
- Shared fields across logical files: the original uses fields shared by views of the same physical file. After a failed lookup, the calculation uses values left by the last successful read through either view. 2A and 2C share that state. In this program, 2B has a separate buffer and can use an older value.
This is the relevant RPG fragment for the second case, with names replaced:
Chain (Item:Product) LogicalFile;
If Factor = 0; Factor = 1; Endif;
RawQuantity = ParentQuantity * RequiredQuantity * Factor;
There is no found check between the lookup and the calculation. The source’s shared fields are therefore part of the behavior. A client can ask for a redesign, but silently giving each view its own Java object changes the calculation.
Where the file is positioned after a failed lookup
Each run of SMALL wrote its own small runtime imitating the file operations of IBM i, and so each one had to decide a number of details that in RPG nobody thinks about, because the system takes care of them. One of these is where a file is positioned after a keyed lookup that does not find anything. In 2B, the lookup that fails simply forgets the position:
found = false;
current = null;
pos = null;
and the following sequential read interprets the absence of a position as a request to start from the first record:
AccessPath.Pos e = pos == null ? path.first() : path.higher(pos);
2A and 2C instead mark the position as not valid, and the next read arrives at the end of the file. It looks like a detail, but there is a program that performs a lookup which fails and then reads the next record: with a single record in the file, 2A and 2C return normally while 2B keeps processing the same record forever. Nobody would list “position after a failed CHAIN” among the design decisions of a migration, and yet it is one, and here it was taken three times with two different outcomes. We found a second program that never ends when we built a bill of materials in which a product contains itself, which is wrong data but the kind of wrong data somebody enters sooner or later: 2B and 2C never come out of it, while 2A at some point stops with an overflow error.
How programs call each other
The same CL call has these forms. The names have been replaced consistently.
2A. Passes a target name and a Ref argument.
protected void run(Ref... parms)
...
call("PROGRAM", passType);
2B. Calls the Java class directly with a String for this known target.
public static void call(Job job)
...
ChildProgram.call(job, passType);
2C. Passes a target name and a CharField argument.
public void call(Field... parms)
...
call("PROGRAM", passType);
2B still has a registry for dynamic and external calls. One may wonder why?, but, you know, sometimes the answer is just because. There is also a practical reason for a mixture: some source targets are known in advance, while others are supplied as data.
In this example, the call is recognizable in every version. Elsewhere, though, 2B passes copies where the RPG passes parameters by reference. The current missing-program stubs do not change those values, so the defect is latent: it becomes relevant when the real callee writes back. The choice of a registry is open; preserving changes returned through parameters is part of the source contract.
How long a program instance lives
The registry is also where we find another decision: reuse an activation or construct a program every time?
2A. Looks up activations by name and retains or removes them according to their active state.
Program p = activations.get(name);
if (p == null) {
p = registry.apply(name);
...
}
...
if (active) activations.put(program, instance);
else activations.remove(program);
2B. Caches activations by Java class and removes them when the last-record indicator is set.
RpgProgram p = activations.get(cls);
if (p == null) {
p = factory.apply(this);
activations.put(cls, p);
}
...
if (p.inlr) {
activations.remove(p.getClass());
p.closeFiles();
}
2C. Invokes the registered constructor factory on each call.
reg("PROGRAM", ChildProgram::new, "********");
...
Entry e = PROGRAMS.get(name.toUpperCase());
...
return e.factory().apply(job);
All of SMALL’s RPG programs end with the last-record indicator on, so for this application the three strategies are equivalent. A different implementation is not necessarily a defect. For an application that keeps state between calls, we would have to preserve that lifetime. In a Java service, we would also need to decide which state belongs to a job and which, if any, is shared by concurrent requests.
Where data areas are stored
All SMALL runs keep file records in memory and save them as CSV. Data areas, the small named pieces of shared data used by the programs, are persisted differently. The excerpts show loading and path selection; cache and error-handling code is omitted.
2A. Loads a shared properties file and retrieves a data area by key.
return db.dataDir().resolve("********.properties");
...
dataAreas.load(in);
...
String v = dataAreas.getProperty(name.toUpperCase(Locale.ROOT));
2B. Uses a text file per data area; without a directory or a file, this path returns an empty string.
Path p = dir == null ? null : dir.resolve(key + ".dtaara");
...
v = p != null && Files.exists(p)
? Files.readString(p, StandardCharsets.UTF_8)
.replaceAll("[\\r\\n]+$", "")
: "";
2C. Also uses a text file per data area, under the configured directory.
Path f = dataDir.resolve(n + ".dtaara");
...
return Files.exists(f)
? Files.readString(f, StandardCharsets.UTF_8)
.replaceAll("[\\r\\n]+$", "")
: "";
Look at what happens in the excerpts above when the data area is not there: 2B and 2C return an empty string and the program continues with it, while 2A stops with the error that IBM i would raise. So the choice of how to store a data area came together with a choice on what its absence means, which is a difference in behavior and not just in format.
To run the same test on the three translations, we had to write an adapter for each one, because each one stores the data in its own way. The representation on disk is a new design choice; the values visible to the program still have to match. The original environment and access by other jobs matter when deciding what should replace a data area.
There was no database or production dataset in the container, and the prompt asked for something runnable. That helps explain the CSV choice. Whether the production target should keep DB2 or move elsewhere is a question the experiment left open. Article 5 returns to it.
How the application starts
Even the command line differs. The jar and program identifiers are masked.
2A. Selects the program with a run subcommand.
java -jar ********.jar --data ./data run ********
2B. Uses --data=... followed by the program.
java -jar ********.jar --data=./data ********
2C. Takes the data directory as a separate argument, followed by the program.
java -jar ********.jar --data ./data ********
The scripts that operate the system need an agreed interface. RPG does not decide the syntax of a new Java launcher, but existing scheduling and operational practices may constrain it. So, three applications that mostly do the same thing, and you cannot swap a single class between them. Not even the script that starts them.
And in 2B there is a program that cannot be started from the command line at all, because the code connecting the launcher to the program passes a string where a number is expected and everything ends with a ClassCastException. The same program works when the nightly job calls it.
Not even the entry points are the same
Experiment 1 gives a shorter example. These declarations are from the same batch program:
Entry methods in the five-program experiment
| Run | Declaration | Connection supplied |
|---|---|---|
| 1A | public static int run(Connection con) throws SQLException |
To a static method |
| 1B | public int run(Connection con) throws SQLException |
To an instance method |
| 1C | public int run() throws SQLException |
Through the constructor |
1A and 1B put SQL operations directly in the program; 1C introduces file and record adapters. 1A and 1B also target Java 17, while 1C targets Java 21. The programs use similar libraries, but these interfaces are not drop-in replacements for the same caller. The target Java version and invocation contract belong among the instructions a team agrees before integration.
Who commits transactions?
A successful test will never show this one. What happens when a database operation fails halfway through a program? The three translations of experiment 1 have three different answers:
Transaction policies in the translated code for experiment 1
| Run | Without SQL errors | After an SQL error |
|---|---|---|
| 1A | Commit at normal completion if auto-commit is off | No explicit commit on the failing path; the connection mode determines what was already persisted |
| 1B | Turn auto-commit off and use a transaction for the program | Roll back on SQLException |
| 1C | Commit if auto-commit is off, inside finally in the reviewed program | Commit also runs after an error |
1C commits in a finally block, so it commits also when the program fails. Whatever was written before the error stays in the database: half an operation, made permanent. Someone will have a lot of fun reconciling that on a Monday morning. 1B, instead, rolls everything back.
We then tried it for real, making the database refuse the update of the third record out of five: the three runs left 4, 0, and 2 records updated, respectively. The 4 of 1A deserves an explanation, because it comes from yet another decision: 1A does not send each update when the original would, rather, it collects them and sends them together at the end, so that when one of them fails, the following ones are applied anyway, and the program ends up updating records that come after the one that failed. The original has no commit control, so on IBM i the records updated before the failure would be written to the database and the job would stop there, which is what 1C does in this specific test.
Nothing in the RPG code says who owns the commit in the new architecture, and we cannot pick the winner by counting which runs agree. The caller may already have work on the connection, or the business operation may span several program calls. That context is something to establish with the client and encode in the target API.
The same input, a different century
On ordinary inputs, the translations of experiment 1 agree. So we went looking for trouble and passed a negative number where a date is expected. With real dates, this never happens; it is an edge test of how the code interprets overlapping numeric fields. We passed (-10181, 0):
Parameters after the call
| Run | First parameter | Second parameter |
|---|---|---|
| 1A | -10181 | 20810101 |
| 1B | 10181 | 19810101 |
| 1C | -10181 | 20810101 |
Return expressions from the numeric helpers
| Run | Expression |
|---|---|
| 1A | return neg[to - 1] ? -v : v; |
| 1B | return Math.abs(v) % mod; |
| 1C | return negativeZone[to - 1] ? -value : value; |
1B takes the absolute value. 1A and 1C preserve the sign in the numeric storage, including the part that affects the century decision. Reading the RPG’s zoned, overlapping fields, 1A and 1C are right, and the corresponding translation inside LARGE does the same. For this program we could afford an exhaustive check: on all the valid non-negative inputs, about 102 million of them, the three translations agree, and on the negative ones 1B differs every time. Will a real user ever hit a negative date? Probably not. But it shows that “the same translation, done again” can disagree on a sign.
Which inputs get checked
Another decision that each run takes on its own is how much to trust what arrives from outside. One program of experiment 1 can be told, through an override, to work on a different table. 1A and 1C verify that what they receive looks like the name of a table before using it, while 1B takes it as it is and puts it inside the SQL statement it then executes. Similarly, on one screen 1B accepts 10 or 12 typed in a field as if the operator had pressed F10 or F12, and 1A accepts the Roll keys although the original screen does not enable them. None of these checks are in the RPG code, because on IBM i the system performs them, so in the Java somebody has to decide to add them, and the agent decided each time differently.
Preserve a bug, or fix it?
In a migration, the usual answer is to preserve it, because somebody may be relying on it, and in most cases this is what the agent did: all the translations reproduce, for example, a MOVE that fills a field with spaces and that almost certainly was a mistake by the original programmer. But in one program in LARGE, the agent took the opposite decision. The original declares a flag telling whether the input is valid and never sets it to “not valid”, so the check after the validation is always passed:
C Exsr Validate
C If VALID = 'N'
C Goto Screen1
C EndIf
In the Java version, the validation returns a result and the caller obeys it:
if (!validate()) {
continue;
}
The operator who types a code that does not exist and presses F9 was let through by the original and is now stopped. It is probably what the programmer wanted, but it is a change in behavior that nobody requested and that is not reported anywhere. Whether to fix the bugs found along the way is a legitimate decision, as long as it is the client taking it.
What happens when source is missing?
SMALL calls programs whose source was not supplied. This is pretty common in a migration, where not all the code is always retrieved. The agent can either leave a stub or infer what a missing program should do, and a plausible inference can make the whole job look much more complete.
Two missing dependencies in SMALL, described without their names
| Missing operation | 2A | 2B | 2C | What the source establishes |
|---|---|---|---|---|
| Forecast preparation | Reconstructs a sequence of existing calculations, with a work-file clear | Stub; does not rebuild the forecast | Reconstructs the calculations in a different order | The caller exists; the missing implementation cannot establish the correct sequence |
| Reset of the running flag | Sets the flag to N | Stub; leaves Y | Stub; leaves Y | The name suggests a reset, but its implementation is missing |
The tests even endorse the different flag outcomes: 2A expects N, while 2B and 2C expect Y. Three runs, three test suites, all green, two different answers. Which one is right? The missing program cannot tell us.
The effect is visible as soon as we run the whole nightly job, the chain of programs that plans the production, on the same and perfectly ordinary data:
| Run | Planned quantities | “Still running” flag at the end |
|---|---|---|
| 2A | 22, 22, 5 | N |
| 2B | 2, 2, 0 | Y |
| 2C | 22, 22, 5 | Y |
These two guesses explain some of the differences we see when we run the whole nightly job on the three translations. When we modified copies of the three so that the two missing programs behave in the same way, the database turned out to be identical after each of the 38 steps of the job, on five of the six sample databases. So the 48 programs for which the source was available agree with each other on this data, and what makes the three applications diverge is what each run invented for the parts it did not have. On those modified copies we also ran the job on 518 databases altered at random, and the three translations finished with the same data on 506 of them, the other 12 being explained by a numeric overflow, where 2A stops and the others continue, and by records with equal keys, which 2A reads in a different order.
The same issue appears with a site-defined edit code: two runs format dates with slashes and one with hyphens, but the site’s definition is absent. The next step is to recover the source or the operating rule from the client. Choosing an expected result from the translated program would only preserve the guess.
Some runtime rules are more concrete. When copying an empty file, 2A raises the escape error that IBM i raises, while 2B and 2C proceed. When clearing a missing member, 2B raises the expected error, while 2A and 2C create the member. So 2A is not right in every case either.
The decisions that did not change
So far, differences. But some decisions were the same in every run, and they are the bigger, more strategic ones. I checked the build files of all seven translations:
Strategic choices across all translations
| Translation | Java version | Build | Application framework | Runtime dependencies |
|---|---|---|---|---|
| 1A, 1B | 17 | Maven | None | H2; IBM Toolbox for Java declared but never used |
| 1C | 21 | Maven | None | H2; IBM Toolbox for Java declared but never used |
| 2A, 2B, 2C | 21 | Maven | None | None |
| LARGE | 21 | Maven | None | H2 |
No run used Spring Boot or any other framework. Each one wrote its own small runtime instead, imitating the IBM i where needed. Apart from JUnit for the tests, the translations of SMALL depend on nothing at all. And the Java versions are long-term support releases, 17 or 21: sensible, but not the latest.
Left to ourselves, we would have built a decidedly different application:
- Java 25, the latest LTS release, out for more than a year now.
- Gradle rather than Maven.
- Spring Boot rather than a hand-written runtime.
- PostgreSQL, certainly not H2, and certainly not CSV files.
Are we right? Honestly, the right answer is “it depends”. We would have to ask the client and look at their situation: what the rest of their systems use, what their developers know, where the data has to live. But these are the choices we typically see our clients make, and the ones we would lean towards. The agent did not lean that way, every single time.
There is one more decision that was the same everywhere, and this one is simply wrong. A program of experiment 1 prints the contacts in the order of their key, and all four of its translations (1A, 1B, 1C and the one inside LARGE) leave the ordering to the database, with an ORDER BY on the key. On IBM i, character keys are sorted in EBCDIC, where lowercase letters come before uppercase ones and both come before the digits, so with the keys 0, A, and a, the original prints a, A, 0 and all the translations print 0, A, a. Comparing the runs with each other would never reveal it, because they agree.
The point is that uniform does not mean decided by us. These choices are the same in every run, so they do not show up when comparing the translations. They are still decisions, and among the most consequential ones.
What about decisions inside a single large translation?
Everything so far compares separate runs. LARGE was translated only once, but in 49 separate sessions, so the same question can be asked about it: did all the sessions take the same decisions? The short answer is that they did not, and that nobody went back to align them, with the same utility written again in dozens of programs and generated files that no longer correspond to their generator. It is a long enough story to deserve its own article, which is article 4.
The decisions to discuss
Some decisions are about the form of the target application. Others are about preserving behavior already specified by RPG. Here is the list I would take into the discussion with the client, after looking at these examples.
Decisions exposed by the translations
| Decision | What the runs did | What depends on the client |
|---|---|---|
| File definitions | Runtime DDS parsing or generated Java metadata | Which definitions must change at runtime, and what developers need to navigate |
| Fields and arithmetic | Generic slots, Java members, or RPG field objects | The API and maintenance style; overflow and padding must follow the agreed source behavior |
| Shared buffers | Shared pools or explicit copies between records | Whether preserving the old state model is the goal, or redesign is authorized |
| Record cycle | Implicit runtime cycle or visible loops | The preferred shape of the Java and the source constructs that must be supported |
| Calls and instances | Registries or direct calls; retained or fresh instances | Integration interfaces and job lifetime, with parameter write-back preserved |
| Persistence | CSV-backed memory for SMALL; JDBC and H2 elsewhere | Production database, data migration, concurrency and operational requirements |
| Transactions | Different commit and rollback policies | Who owns the transaction and what has to succeed together |
| Launchers and packages | Different flags, entry methods and package trees | Scheduling, deployment and team conventions |
| Missing dependencies | Stubs or inferred replacements | Who can supply the missing implementation or approve a replacement |
| Screens and reports | Console screens and text spool output | The interface users will actually work with |
| Runtime and dependencies | Agent-written runtime; no application framework | Framework expectations and responsibility for long-term runtime maintenance |
| Generated files | Generators shipped alongside outputs that can differ | Whether changes belong in generators, generated Java or explicit overrides |
| Verification | Tests encode each run’s own assumptions | Who establishes the expected results and signs off intentional changes |
The importance of decisions
Let’s step back for a moment. We start a migration when we have a system that is useful to the company but a problem with its technology. Think of an ERP that tracks what is in the warehouse and sets the price of each product. We want the software to keep doing that, but we want to change the technology, and often for business reasons:
- Cost and organization. The language runs only on certain hardware, or needs certain software licenses, and we want to get rid of them.
- Skills. We struggle to find, or to keep, people who know the legacy technology.
- Uniformity. The rest of our systems use another technology, or we acquired a company, or were acquired by one, and we want to converge on a single stack.
- Evolution. We expect a different technology to integrate more easily with other systems, cost less to maintain, and let us change the software faster.
- Scalability and performance. The system cannot handle more users, or the batch jobs that run every night take longer as the business grows, until the night no longer lasts enough.
Each of these needs has consequences for the life of the company. On top of that, if we are doing a migration, we want to do it as well as possible, which means producing code that is easy to maintain for the people who will actually maintain it.
Two translations that both behave like the original can serve these needs very differently. So a migration is full of design decisions, and somebody has to take them. If we give the LLM no instructions, it takes them for us.
The ones we saw here are mostly about code organization, and fairly low-level. Some alternatives work equally well. Some introduce defects. Others cannot be judged without context the agent never had. And they change from one run to the next. The bigger, strategic ones do not change, but nobody discussed them either: no framework, a hand-written runtime, Java 17 or 21.
Conclusions
Before going to what I make of all this, let me put together the main things we have seen in this article:
- The same prompt gives a different application each time. The three translations read and write the same files in the same order, but less than half of their Java is the same, and you cannot move a single class from one to the other.
- Small decisions change the behavior. The type chosen for one variable decides whether a program stops with an error, writes 1000 or writes nothing, and the position of a file after a failed lookup decides whether a program terminates.
- Some behavior comes from the platform and is not written in the RPG code. On IBM i, the operating system takes care of transactions, of the order in which records are read, of validating the data coming from outside and of what happens when a data area does not exist, so the RPG programmer never had to write any of this. In Java somebody has to write it, and since the source does not say how, each of the three runs handled these aspects differently.
- When something is missing, the agent guesses. Where the source of a program was not available, one run wrote an empty placeholder and the others reconstructed it, each differently, and the tests written by each run confirm its own guess.
- Bugs are mostly preserved, but not always. In at least one program, the agent fixed a defect of the original without being asked and without reporting it.
- The major decisions are not what a software architect would have picked. No framework, a runtime written by hand, Maven, Java 17 or 21, CSV files or H2: these were the same in every run, and they are not what our clients or we would have chosen.
- Inside a large translation, decisions are taken session by session. Later sessions improve the runtime and do not go back to apply the improvement, the same construct is translated differently at the beginning and at the end, and utilities are written again in each program instead of being shared. This is the subject of article 4.
- Even the generators written by the agent drift. About 30 of the generated files no longer correspond to what their own generator produces.
Good choices need context, where “the context” is what cannot be derived by looking at the application. It is information that includes the presence of other systems, the plans the company has for the next years, on what the team knows. A person planning the migration collect it by going around and reasoning with the client. Then, while the work progresses, a good consultant stops when something comes up: this decision is worth discussing, this point needs more investigation. An LLM cannot do that: it keeps going, and picks a “vanilla” solution. So it is our job to feed it the right context.
One may wonder if these design decisions matter at all.
I think we should distinguish two kinds of decisions:
- Decisions that affect external properties: how much it costs to perform a certain change on this codebase, how complex it is, how fast it runs, which database or infrastructure it requires. These are relevant dimensions for the business and I would expect them to matter for quite some time.
- Decisions that regard taste, maintainability, or the knowledge of the team. Perhaps one day these will matter less or not at all, if code becomes a black box, an artifact we do not look at. I believe we are not there yet, but who knows where we will stand in six months?
But for now, as the mechanical translation becomes more and more, so to speak, a given, the decisions are where the difference is made. That is where it is worth spending our time. Article 5 is about how.
Thank you to Alessio Stalla and Gabriele Tomassetti for their work on this article.
If this was useful, there are more on the same problem.
More in Legacy systems & modernization
Legacy Modernization with LLMs, measured Legacy Modernization with LLMs: Does the Translation Behave Like the Original? Legacy Modernization with LLMs: is a large translation consistent with itself?A legacy estate you need to understand before you commit.
See how Strumenta worksDisclosure — Strumenta is a company I co-founded.