arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2602.21833cs.SE
收藏

从重构到稳定:基于大语言模型的迭代代码可读性重构大规模实验

From Restructuring to Stabilization: A Large-Scale Experiment on Iterative Code Readability Refactoring with Large Language Models

Saarland University(萨尔兰大学)

Norman Peitek, Julia Hess, Sven Apel

AI总结:

本文通过大规模实验研究大语言模型在迭代代码重构中的能力,揭示了重构过程的收敛趋势及可读性提升的机制。

摘要:

大语言模型(LLMs)越来越多地用于自动化代码重构任务。尽管这些模型可以快速重构代码,但其质量可能表现出不一致性和不可预测的行为。本文系统研究了LLMs在代码重构方面的能力,特别是提高代码可读性。我们使用GPT5.1对230个Java代码片段进行了大规模实验,每个片段在五次迭代中,采用三种不同的提示策略,系统地变化和重构代码可读性。我们将重构过程中的细粒度代码更改分为实现、语法和注释层面的转换。随后,我们调查了功能正确性,并用新片段测试了结果的鲁棒性。我们的结果揭示了三个主要见解:首先,迭代代码重构表现出一个重构阶段后稳定阶段的倾向。这种收敛趋势表明,LLMs具有内部化的“最优可读性”代码版本的理解。其次,收敛模式在不同代码变体中相当稳健。第三,明确提示特定可读性因素略微影响重构动态。这些见解为评估LLM辅助代码重构的可靠性提供了实证基础,为未来研究开辟了路径,包括跨模型的比较分析以及系统评估LLM重构代码中的其他软件质量维度。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑