Evaluating AI Coding Assistants for Cross-Language Code Migration: A Fortran-to-C++ Poisson Solver Case Study

    This article presents a practical evaluation of AI coding assistants on migrating scientific computing code from Fortran to C++. It uses a two-dimensional Poisson equation solver from a fluid dynamics textbook as the test case. The four-step workflow treats the original Fortran output as the gold standard. The article compares how two tools handled the index base difference between the languages and proposes a reusable evaluation method based on interaction rounds, result agreement, and failure behavior.

    1. Background and Motivation

    In scientific computing and engineering simulation, many classic algorithms have been preserved in Fortran for decades. The companion solver programs for the authoritative textbook Computational Methods for Fluid Dynamics are a typical example. As modern engineering software stacks move toward C++, Python, and other languages, migrating this legacy code to modern languages has become a practical need for many development teams.

    AI coding assistants have improved quickly in recent years. A common question in the industry is whether these tools can reliably migrate scientific computing code across languages. Unlike typical business code, numerical code is highly sensitive to details such as index bounds, floating-point precision, and loop order. Even a small deviation can cause results to diverge. For this reason, this type of task is a strong test of an assistant’s core coding ability.

    This article summarizes a reusable evaluation methodology based on a controlled comparison experiment. It also analyzes the typical behaviors that different coding assistants showed on this task.

    2. Evaluation Task Design

    2.1 Task Definition

    The evaluation used a case from the textbook: solving the two-dimensional Poisson equation. Each assistant had to complete the following workflow:

    1. Code migration: Rewrite the Fortran solver in C++ while keeping the numerical algorithm and data structure semantics consistent.
    2. Compilation and execution: Compile the program into an executable, run it, and write the results to a text file.
    3. Result verification: Write a Python script that extracts the Fortran baseline results and the C++ results, then compares them numerically and visualizes them.
    4. Iterative repair: If the two results disagree, locate the problem and modify the code until the results match.

    The design has a clear advantage. The task has a strict gold standard, which is the output of the original Fortran program. Whether the results match is objectively verifiable, so the evaluation avoids subjective judgment.

    2.2 Evaluation Dimensions

    • Interaction rounds: The number of conversation turns from the initial request to a correct result. This reflects the assistant’s ability to get the task right on the first attempt.
    • Result agreement: The numerical deviation between the C++ results and the Fortran baseline.
    • Behavioral traits: Softer indicators, including instruction adherence, debugging strategy, and the ability to extend the task proactively.

    3. Experiment and Key Findings

    3.1 A Common Pitfall: Index Base Differences

    The most representative problem in the experiment was the index base difference between Fortran and C++. Fortran arrays start at index 1 by default, while C++ arrays start at index 0. This looks like a basic concept. In numerical code with nested loops, boundary condition enforcement, and grid node mapping, however, indexing offset errors are very hard to spot. The program compiles and runs, and its output magnitude looks reasonable. The field distribution, though, shows a systematic deviation from the baseline.

    One of the tested tools did not handle this difference properly in its first few versions, so its output did not match the baseline. After several cycles of running, comparing, and correcting, the tool identified the index mapping issue and fixed it. The process took about 7 to 8 interaction rounds in total. The other tool produced the correct version within 2 to 3 rounds. It identified and avoided the index base difference during the process.

    3.2 Result Verification

    Both tools completed the task successfully. The C++ results almost fully matched the Fortran baseline. The residual convergence curves and physical field distribution plots were visually indistinguishable. This shows that current mainstream AI coding assistants have the basic ability to migrate scientific computing code of moderate complexity.

    3.3 Behavioral Comparison

    The experiment also revealed notable differences in behavior between the tools:

    • Conservative type: Follows instructions strictly, takes the shortest path, and needs few rework cycles. Its output is adequate but unremarkable, and it does not optimize beyond the task scope on its own.
    • Divergent type: Fluctuates more during the process. When fixing logic errors, it sometimes went back and forth. During the visualization step, however, it generated richer and more expressive charts on its own initiative, showing a stronger sense of task extension.

    Neither style is better in every case. In production environments where predictable results matter, the conservative type is a better fit. In exploratory R&D, the creative output of the divergent type may provide extra value.

    4. A Reusable Evaluation Methodology

    Based on this experiment, we distilled a general framework for evaluating the engineering capability of coding assistants:

    1. Select tasks with a gold standard. Prioritize problems that have authoritative reference solutions, such as classic textbook cases or benchmark suites, so that correctness can be judged objectively.
    2. Cover the full workflow. Test more than code writing. Also test the closed loop of compilation, execution, verification, and debugging.
    3. Record interaction traces. Count the rounds and analyze the error types to measure how efficiently each tool converges on a correct result.
    4. Focus on failure modes. How an assistant fails matters more than whether it succeeds. Check whether it can diagnose problems on its own, whether it gets stuck in loops, and whether its fixes introduce new problems.

    For enterprise teams that want to apply AI coding tools at scale, we recommend building an automated evaluation pipeline on general-purpose cloud infrastructure. Object storage can hold test samples, a container platform can provide a unified runtime environment, a logging service can record interaction traces, and monitoring and alerting can track the status of evaluation tasks. Together, these components turn one-off experiments into a sustainable capability assessment system.

    5. Conclusion and Outlook

    This evaluation shows that mainstream AI coding assistants can handle scientific computing code migration tasks that require strict correctness. However, tools differ significantly in convergence efficiency, sensitivity to detail, and creativity. For Fortran-to-C++ migrations, which involve language-specific pitfalls, first-attempt accuracy still varies widely across tools. Manual verification against a gold standard remains essential.

    As models develop a deeper understanding of programming language semantics and toolchain integration improves, the cost of modernizing legacy scientific computing code may continue to fall. When selecting tools, teams should weigh stability against divergence based on their own scenario, whether production-oriented or exploratory. Teams should also build an objective, reproducible internal evaluation process rather than relying on reputation or single cases.