Editor’s introduction
It compares translation performance using NL-specification alone versus with source code, across five popular languages and 29 language pairs. Results show no consistent improvement when NL-specification is used independently, though it yields benefits in specific cases, such as Python to C++ translations. The study notes that post-generation fixes are limited to compilation errors, which may reduce the assessment of full translation quality under more refined, iterative processes. This boundary limits the generalizability of the findings to settings involving human review or extensive code correction.
Introduction
Migrating legacy codebases through code translation is a challenging yet necessary step in modernizing and adapting software systems to current technologies. The process typically begins with a comprehensive analysis of the original code’s specifications, which provide a detailed blueprint of the code’s intended functionality. These specifications, along with the legacy code itself, serve as critical anchors during the translation process, offering a clear reference for understanding the existing code’s logic and design patterns. By carefully examining the legacy code, key components, such as business rules, data structures, and algorithms, need to be identified, which must be accurately translated into the new language or framework.
For large software systems, manually migrating code is a time-consuming and error-prone process. Hence, there is a growing need for automated approaches to generate code to a target language from the existing codebase, such as from C to Rust. To this end, research efforts are made to automate code translation. Recently, large language models (LLMs) have demonstrated strong capabilities in both code generation and code translation. On the generation side, modern LLMs can synthesize executable code directly from natural language descriptions with high accuracy, achieving state-of-the-art performance on benchmarks such as. These results suggest that LLMs are highly effective at mapping natural language semantics to correct program logic.
In parallel, prior work has explored LLM-based code translation across programming languages. Most existing approaches treat translation primarily as a syntax-preserving transformation task, relying almost exclusively on the source code as context. For example, translate code across multiple languages using GPT-4 with the full source program as input, while incorporate retrieval-based augmentation to assist translation. While effective in many cases, these methods offer limited insight into whether explicitly modeling program intent can improve translation robustness, particularly for semantically complex code.
To better preserve semantics across languages, some studies introduce intermediate representations (IRs) for code translation. Compiler-level IRs such as LLVM IR enable structured, language-agnostic transformations, but are inherently low-level and lack support for many popular languages. More recently, INTERTRANS explores the use of high-level programming languages as intermediate representations for LLM-based translation. While promising, this approach remains constrained by the expressiveness and availability of suitable intermediate languages and does not explicitly separate program intent from implementation details.
Despite these advances, a key gap remains. Unlike compiler-level IRs, which are low-level and language-constrained, or programming-language IRs (INTERTRANS), which require a suitable intermediate language to exist, natural language specifications are universally applicable across all language pairs and are the modality in which program intent is most naturally expressed, and the primary training signal for LLMs. This positions NL-specification as a conceptually distinct intermediate representation whose effectiveness we empirically characterize across success and failure regimes, rather than assuming uniform benefit.
Motivated by this observation, we investigate when and how incorporating natural language specification (NL-specification) affects LLM-based code translation. We hypothesize that NL-specification can (1) expose high-level intent that may be implicit or obscured in source code, (2) complement source code by clarifying semantics for complex control flow or logic, and (3) enable higher-quality target code by allowing generation to focus on intent rather than syntactic correspondence. Unlike prior work, we systematically study translation using source code only, NL-specifications only, and their combination, while limiting post-hoc fixes to compilation errors to better isolate the effect of the NL-specification.
Dataset Validation
We successfully downloaded the CodeNet dataset. For Avatar, while the test cases were available, we were unable to download the corresponding code snippets by following the procedures described in the official GitHub repository, as the download script referenced invalid links. As an alternative, we obtained the code snippets from the artifact released by, which was evaluated and validated by ACM (version 1.1).
During validation, we identified multiple inconsistencies in the Avatar dataset where the expected outputs in the test cases did not match the actual outputs produced by the corresponding source code. In some cases, the expected outputs were incomplete and ended with ellipses (“…”). To address this, we executed the source code to obtain the actual outputs and compared them against the expected outputs using prefix matching, i.e., we checked whether the expected output was a prefix of the actual program output. When the prefix matched, we repaired the test case by replacing the expected output with the complete actual output.
For a small number of instances, no expected output matched the actual program output, making it impossible to construct valid test cases. We therefore excluded these instances from our experiments, consisting of 11 Python files and 10 Java files in Avatar. Overall, we verified and repaired incorrect outputs in the Avatar dataset to ensure test case validity. The dataset cleanup scripts are included in our artifact for transparency and reproducibility. We have named our cleaned Avatar Dataset as Avatar-Verified and published it in our repository. The results reported for the Avatar dataset from the baseline are based on the Avatar-Verified.
Evaluation Results
To evaluate correctness, we use Computational Accuracy (CA), a standard metric commonly used in previous works, to facilitate direct comparison. CA is defined as the ratio of datapoints that pass all corresponding test cases to the total number of datapoints. We consider a translation passed only if all test cases pass for the translated code.
We selected C, C++, Go, Java, JavaScript, Rust, and Python as target languages. We used gcc v11.4.0, g++ v11.4.0, OpenJDK 11.0.25, go v1.23.2 Linux/amd64, node v12.22.9, rustc v1.92.0, and python v3.10.13 to evaluate the translations to C, C++, Java, Go, Javascript, Rust, and Python, respectively. The operating system is Ubuntu 22.04.4 LTS.
RQ1-Can LLM-generated specifications boost LLM-based code translations?
Motivation Previous studies have shown that LLMs can translate code across programming languages with reasonable accuracy. However, code translation remains challenging when the source code is complex, long, or highly language-specific. Natural language (NL) specifications offer a higher-level description of program intent and may help LLMs focus on semantics rather than syntax. If LLM-generated specifications can capture the essential behavior of a program, they may serve as useful intermediate representations that improve translation quality. Therefore, this research question investigates whether using LLM-generated NL specifications, either alone or combined with source code can improve LLM-based code translation compared to using source code alone.
Method To answer this RQ, we first prompted LLMs to generate the NL-specification description for a given code from the dataset. Then we used our three strategies to compare the translation capability: (1) Prompting LLMs to translate code to a target language using only the NL-specification(2) Prompting LLMs to translate code to a target language using only the source code and (3) Prompting LLMs to translate code to a target language using a combination of source code and the corresponding NL-specification. We compare the results of the three above-mentioned approaches with baselines and. We have a total of 1916, 4000, and 164 translations from Avatar-Verified, CodeNet, and Evalplus, respectively.
Results. Tables 7, 8, and 9 report the evaluation results for our three prompting strategies: (i) the source-only baseline, (ii) NL-specification only (NL-specification), and (iii) joint conditioning on source code and NL-specification (NL-specification + Source), using GPT-4, DeepSeek-Coder, and Magicoder, respectively. For each model, we include the corresponding published baselines: Pan et al. for GPT-4, InterTrans for Magicoder, and we report DeepSeek-Coder results as a new model without an established prior baseline.
However, for other language pairs, our strategies do not surpass the baseline. Thus, when aggregated across all datasets and language pairs, the source-only baseline remains the strongest overall, suggesting that while NL-specification can be beneficial in certain scenarios, it does not consistently outperform direct source-based translation.
Across all datasets, the performance differences among the three prompting strategies are relatively small. This indicates that DeepSeek-Coder is less sensitive to NL-spec conditioning and is able to recover much of the required semantic information directly from the source code. One possible explanation is that DeepSeek-Coder has been extensively trained on large-scale, multilingual code corpora, enabling it to internalize common programming patterns and semantics without relying heavily on auxiliary natural language guidance.
We observe that combining source code with NL-specification occasionally provides modest gains for specific language pairs (e.g., Python-to-Java on EvalPlus), suggesting that NL-specification may still offer complementary signals in scenarios involving ambiguous logic or implicit assumptions. Future improvements could focus on selectively applying NL-specification only when source code complexity exceeds a certain threshold (e.g., deep control flow or sparse documentation), or on improving the faithfulness of NL-specification generation to better align with DeepSeek-Coder’s internal representations.
RQ2-When LLM-generated specifications can boost code translation and when not?
Motivation. RQ1 evaluates the quantitative impact of conditioning LLM-based code translation on NL-specification, but does not explain why NL-specification helps in some cases and degrades performance in others. RQ2 complements RQ1 by qualitatively analyzing how the content and correctness of NL-specification influences translation outcomes, using the same LLMs and translation settings. By examining representative cases where NL-specification improves or downgrades translations relative to source-only prompting, RQ2 aims to uncover concrete success patterns and failure modes that explain the trends observed in RQ1.
Method. To answer RQ2, we first conducted a manual analysis on 100 translations. For each source language (C, C++, Go, Java, and Python), we selected ten translations where using NL-specification led to correct results while using source code did not, and ten where the opposite occurred, NL-specification produced incorrect results while source code succeeded. This resulted in 20 samples per language, covering both cases of NL-specification impact.
We also conducted a manual analysis on 250 generated NL-specification (50 for each programming language from C, C++, Go, Java, Python). Two annotators, both co-authors of this study and graduate students with over six years of professional software development experience, independently analyzed the selected samples using thematic coding. Thematic coding is a qualitative analysis method in which recurring patterns or themes are iteratively identified, refined, and categorized based on close inspection of the data, rather than being predefined in advance. Each annotator first performed open coding to identify potential themes related to the effect of NL-specification on translation outcomes, followed by iterative refinement to consolidate and name the final themes.
Results. After manually analyzing 250 NL-specification samples, we found that 87.2% (218/250) were correct, while 12.8% (32/250) were incorrect. For the 32 incorrect NL-specification instances, the NL-specification-only strategy always results in incorrect translations, whereas combining source code with NL-specification (source+NL-specification) leads to correct translations in 15 cases.
Among the 232 instances with correct NL specifications, 81.0% (188/232) produced correct translations when using NL-specification only, while 84.1% (195/232) produced correct translations when combining source code with NL-specification. This shows that when NL-specification is generated correctly, it improves translation accuracy, and that combining NL-specification with source code further increases robustness by mitigating errors introduced by imperfect specifications.
In the separate manual inspection of 100 translated instances, we observed that NL-specification-only produced correct translations in cases where the LLM-generated NL-specification correctly simplified complex source code, while the corresponding translations generated using source-code-only were incorrect. This suggests that simplified explanations of complex source code can enable correct translations.
RQ3-What is the impact of specifications on the quality of translated code?
Motivation. Previous studies, such as Pan et al. (2024), have established baselines for code translation, but the impact of input modality on code hygiene is not well understood. We hypothesize that the nature of the input, specifically the use of high-level NL-specifications versus low-level source code, might influence the LLM’s adherence to language-specific best practices. RQ3 aims to quantify this impact. By analyzing the density of Critical and Blocker issues across our different experimental setups (NL-specification, source code, and NL-specification with source code), we assess whether explicit specifications help mitigate common static analysis warnings found in standard translation approaches.
Results. Tables 12 and 13 show detailed results before and after repair, respectively, for all three models across the three datasets and all language pairs. Both tables report the number of critical and blocker issues per 1000 NCLOC. Overall, the number of issues remains largely unchanged before and after repair, regardless of whether NL-specification only or NL-specification combined with the source code is used. Additionally, for a given dataset and language pair, the number of issues varies only slightly across different LLMs. However, some differences between LLMs are noticeable: for most language pairs, Magicoder tends to have a slightly higher number of issues compared to the other two LLMs, while GPT-4 generally has fewer issues. An exception is observed in the evalplus dataset, where GPT-4 produces more issues than the others. Another notable trend is that translations into the C language show a higher increase in issues compared to other language pairs, indicating that C code is more prone to vulnerabilities.
As shown in the figure, the prevalent issues vary significantly depending on the target language. In C and C++, the most frequent issue is Split Declaration, which refers to defining multiple variables in a single statement (e.g., int a, b;) rather than using dedicated statements to improve readability and maintainability. In Go, the results are dominated by Invalid Variable Names, which violate the language’s specific naming conventions (such as camelCase or underscore patterns), and High Cognitive Complexity, which indicates that the control flow is too difficult to follow due to deeply nested loops or conditionals. For Java, the primary issues are Use Logger, the recommendation to replace System.out with a logging framework, and naming violations for packages, classes, or variables. In Python, Potential IndexError is most common, indicating collection access that may exceed bounds due to mismatched indexing logic during translation.
Generally, the source language does not significantly impact the frequency of issues in the target language. However, some exceptions exist: for instance, Invalid Variable Names are notably more frequent when translating from Python to Go, while Split Declarations are less common in C to C++ translations compared to other source languages.
The top issue messages from SonarQube indicate several code quality and security issues in the C language. Key concerns include unsafe memory access (e.g., using tainted values for array indexing or division), improper use of functions like strtok (which should be replaced with strtok_r for thread safety), and violations of C standards (e.g., implicit function declarations). This indicates that the language model is not highly concerned with the detailed and complex structure of the C language.
Conclusion and Future Work
In this work, we experiment with two approaches for translating source code from one programming language to another: one using NL-specification as an intermediate representation and providing it as a prompt to an LLM to generate code in the target language, and another combining NL-specification with the source code to generate target language code and also fix compilation errors using the LLM. We found that the approach combining source code with NL-specification yields gains over the baseline on certain datasets and specific source languages, while the source-only baseline remains the strongest strategy overall when aggregated across all language pairs. We analyzed the reasons behind the successes and failures of both approaches, as well as the quality of the translated code, identifying issues with the translation of C language code. In the future, we aim to enhance our approaches by addressing the root causes of failures and refining the intermediate representation. As future work, we also plan to extend our approach to repository-level code translation and improve performance in modest areas by incorporating Spectrum-Based Fault Localization (SBFL) techniques.


