Code Refactoring with LLM: A Comprehensive Evaluation With Few-Shot Settings
Md. Raihan Tapader, Md. Mostafizer Rahman, Ariful Islam Shiplu, Md Faizul Ibne Amin, Yutaka Watanobe

TL;DR
This paper evaluates a large language model-based framework for multilingual code refactoring, demonstrating high correctness and compilability across languages with few-shot learning and prompt engineering.
Contribution
It introduces a novel LLM-based, prompt-engineered, few-shot approach for accurate, multilingual code refactoring, addressing limitations of traditional rule-based methods.
Findings
Java achieves up to 99.99% correctness in 10-shot setting.
Refactored code maintains high similarity (~53-54%) and improves compilability (~94.78%).
Python shows minimal structural distance with moderate similarity.
Abstract
In today's world, the focus of programmers has shifted from writing complex, error-prone code to prioritizing simple, clear, efficient, and sustainable code that makes programs easier to understand. Code refactoring plays a critical role in this transition by improving structural organization and optimizing performance. However, existing refactoring methods are limited in their ability to generalize across multiple programming languages and coding styles, as they often rely on manually crafted transformation rules. The objectives of this study are to (i) develop an Large Language Models (LLMs)-based framework capable of performing accurate and efficient code refactoring across multiple languages (C, C++, C#, Python, Java), (ii) investigate the impact of prompt engineering (Temperature, Different shot algorithm) and instruction fine-tuning on refactoring effectiveness, and (iii) evaluate…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Software Testing and Debugging Techniques · Logic, programming, and type systems
