Large language models (LLMs) are increasingly used for automated code refactoring tasks. Although these models can quickly refactor code, the quality may exhibit inconsistencies and unpredictable behavior. In this article, we systematically study the capabilities of LLMs for code refactoring with a specific focus on improving code readability.
We conducted a large-scale experiment using GPT5.1 with 230 Java snippets, each systematically varied and refactored regarding code readability across five iterations under three different prompting strategies. We categorized fine-grained code changes during the refactoring into implementation, syntactic, and comment-level transformations. Subsequently, we investigated the functional correctness and tested the robustness of the results with novel snippets.
Our results reveal three main insights: First, iterative code refactoring exhibits an initial phase of restructuring followed by stabilization. This convergence tendency suggests that LLMs possess an internalized understanding of an "optimally readable" version of code. Second, convergence patterns are fairly robust across different code variants. Third, explicit prompting toward specific readability factors slightly influences the refactoring dynamics.
These insights provide an empirical foundation for assessing the reliability of LLM-assisted code refactoring, which opens pathways for future research, including comparative analyses across models and a systematic evaluation of additional software quality dimensions in LLM-refactored code.
Humanizing Automatically Generated Unit Test Suites with LLM-Based Refactoring
University of Luxembourg(卢森堡大学);Nanjing University of Science and Technology(南京理工大学);Zhejiang University(浙江大学);Bilkent University(比尔肯特大学);Singapore Management University(新加坡管理大学)
Refactoring for Novices in Java: An Eye Tracking Study on the Extract vs. Inline Methods
State University of Paraíba (UEPB)(帕拉伊巴州立大学);Federal University of Campina Grande (UFCG)(坎皮纳格兰德联邦大学);Federal University of Alagoas (UFAL)(阿拉戈阿斯联邦大学);University of Brasília (UnB)(巴西利亚大学);Pontifical Catholic University of Rio de Janeiro(里约热内卢天主教大学)
CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkit
The Hong Kong University of Science and Technology(香港科技大学);Institute of Software Chinese Academy of Sciences(中国科学院软件研究所);University of Chinese Academy of Sciences(中国科学院大学)