Conference paper

TranSCoT: Towards Improving Quality of Code Translations

Abstract

Large language models (LLMs) offer a promising, faster and cost- effective approach to code translation. Existing research work on code translation assumes improving functional accuracy of the translated code as the primary objective. In this paper, we argue that while it is crucial that the translated code be functionally accurate, it is not the only important factor in code translation, particularly when the translation task involves multiple interde- pendent source files rather than isolated programs or code snippets. Maintaining a broad structural equivalence with the original source code is desirable for higher quality, maintainable, compatible, and easily integrable codes. We present TranSCoT, a novel and easy-to- implement technique, that leverages a chain-of-thought reasoning to create systematic prompts that steer LLMs through the code translation process. TranSCoT not only enhances functional accu- racy by reducing numerous compilation errors but also ensures that the translated code maintains a broad structural resemblance to the original source, thereby improving maintainability and understand- ability. Additionally, we introduce a novelquality metric to assess code translation quality by evaluating structural similarities be- tween the source and translated code. We empirically demonstrate the efficacy of TranSCoT prompting approach through evaluations over several benchmarks. For various open-source LLMs, TranSCoT prompts yield translations of significantly higher quality, both struc- turally and functionally, compared to the existing state-of-the-art prompting techniques.