Abstract:Many software projects implement APIs and algorithms in multiple programming languages. Maintaining such projects is tiresome, as developers have to ensure that any change (e.g., a bug fix or a new feature) is being propagated, timely and without errors, to implementations in other programming languages. In the world of ever-changing software, using rule-based translation tools (i.e., transpilers) or machine learning models for translating code from one language to another provides limited value. Translating each time the entire codebase from one language to another is not the way developers work. In this paper, we target a novel task: translating code changes from one programming language to another using large language models (LLMs). We design and implement the first LLM, dubbed Codeditor, to tackle this task. Codeditor explicitly models code changes as edit sequences and learns to correlate changes across programming languages. To evaluate Codeditor, we collect a corpus of 6,613 aligned code changes from 8 pairs of open-source software projects implementing similar functionalities in two programming languages (Java and C#). Results show that Codeditor outperforms the state-of-the-art approaches by a large margin on all commonly used automatic metrics. Our work also reveals that Codeditor is complementary to the existing generation-based models, and their combination ensures even greater performance.
What problem does this paper attempt to address?
### Problems the paper attempts to solve
This paper aims to solve the problem of code change synchronization in multilingual software projects. Specifically, when a software project implements the same functionality in multiple programming languages, developers need to ensure that any changes (e.g., bug fixes or new feature additions) can be propagated to the implementations in other programming languages in a timely and error - free manner. Currently, developers usually complete this process manually, which is time - consuming and error - prone. Although there are some rule - based conversion tools and machine - learning models that can attempt to translate code, these methods either require frequent rule updates or are unable to accurately infer project - specific data types and class names, and thus have limited effectiveness.
To address this challenge, the paper proposes a new task: using large - language models (LLMs) to translate code changes in one programming language into the corresponding changes in another programming language. The author designed and implemented the first large - language model specifically for this task, named **Codeditor**. Codeditor explicitly models code changes as edit sequences and learns related changes across programming languages.
### Main contributions
1. **Task definition**: Proposed a new task, that is, automatically generating the corresponding changes in another programming language based on code changes in one programming language.
2. **Model design**: Designed and implemented **Codeditor**, which is the first large - language model capable of aligning edits across programming languages and explicitly performing edits on old code in the target language.
3. **Dataset creation**: Created the first dataset containing aligned code changes in two programming languages (Java and C#), extracting 6,613 pairs of code changes from 8 open - source projects.
4. **Experimental results**: The experimental results show that Codeditor significantly outperforms existing models on all commonly used automatic evaluation metrics. In addition, it was found that Codeditor and generative models are complementary, and their combined use can further improve the accuracy rate.
### Method overview
1. **Task definition**: Given the old code \( M_S^{old} \) and new code \( M_S^{new} \) in the source language, and the old code \( M_T^{old} \) in the target language, the task is to generate the new code \( M_T^{new} \) in the target language so that its functionality is consistent with \( M_S^{new} \).
2. **Model architecture**: Codeditor is based on the encoder - decoder framework, with initialization parameters from the pre - trained language model CoditT5. It adapts to the multilingual collaborative editing task through fine - grained context inputs (source - language code changes, target - language old code, source - language new code) and two output formats (directly generating target - language code changes, generating meta - edit sequences).
3. **Dataset**: Aligned Java and C# code changes were extracted from 8 open - source projects to construct a dataset containing 6,613 pairs of code changes. The dataset is divided into training sets, validation sets, and test sets. See Table 3 for detailed statistics.
### Experimental results
- **Performance comparison**: Codeditor significantly outperforms existing models on all selected automatic evaluation metrics, especially in exact - match accuracy, which is 77% higher than that of existing generative models.
- **Complementarity**: Codeditor performs better when dealing with longer code fragments, while generative models perform better when dealing with shorter code fragments. Combining the two can further improve the exact - match accuracy of Codeditor by 6%.
### Conclusion
This paper effectively solves the problem of code change synchronization in multilingual software projects by proposing new tasks, designing specialized models, and creating datasets, providing strong support for the collaborative work of software developers.