1
Return

Refactoring with LLMs: Bridging human expertise and machine understanding

delete2026-07-25
delete0
PRE
AI
Y
Yonnel Chen Kuang Piao
J
Jean Carlors Paul
L
Léuson Da Silva *
A
Arghavan Moradi Dakhel
M
Mohammad Hamdaqa
F
Foutse Khomh
DOI:10.1007/s10664-026-10925-0delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
Code refactoring is a fundamental software engineering practice aimed at improving code quality and maintainability. Despite its importance, developers often neglect refactoring due to the significant time, effort, and resources it requires, as well as the lack of immediate functional rewards. Although several automated refactoring tools have been proposed, they remain limited in supporting a broad spectrum of refactoring types. In this study, we explore whether instruction strategies inspired by human best-practice guidelines can enhance the ability of Large Language Models (LLMs) to automatically perform diverse refactoring tasks. Leveraging the instruction-following and code comprehension capabilities of state-of-the-art LLMs (e.g., GPT-mini and DeepSeek-V3), we draw on Martin Fowler’s refactoring guidelines to design multiple instruction strategies that encode motivations, procedural steps, and transformation objectives for 61 well-known refactoring types. We evaluate these strategies on benchmark examples and real-world code snippets from GitHub projects. Our results show that instruction designs grounded in Fowler’s guidelines enable LLMs to successfully perform all benchmark refactoring types and preserve program semantics in real-world settings–an essential criterion for effective refactoring. Moreover, while descriptive instructions are more interpretable to humans, our results show that rule-based instructions often lead to better performance in specific scenarios. Interestingly, allowing models to focus on the overall goal of refactoring, rather than prescribing a fixed transformation type, can yield even greater improvements in code quality.
Keywords:
Refactoring
Large Language models
Prompt Engineering

Journal

Empirical Software Engineering cover
Empirical Software Engineering
IF:
3.6
Papers:
1.9K
Citations:
5.3K

Organization

Cited Papers

Cited Papers

Citing Papers

Citing Papers