一句话:首次提出整体化代码可读性改进方法,构建122k提交数据集并训练T5自动建议可读性改进。
代码阅读占开发者日常活动的大部分,已有研究多聚焦于自动评估代码可读性或修复命名、格式等特定问题,但仍缺乏自动建议整体可读性改进动作的方法。本文提出首个整体化可读性改进方案:首先定义自动识别“可读性改进提交”的方法,并挖掘GitHub 2015至2022年全部项目历史,构建包含122k提交的数据集,识别准确率约86%;其次训练并测试T5模型,以模仿开发者改善可读性的编辑行为。评估显示,模型完全预测准确率在21%至28%之间;对500条预测的人工评估表明,当模型不改变输入行为且实际应用修改时(占34%),其中79.4%的情况确实提升了代码可读性。
Reading source code occupies most of developer's daily activities. Any maintenance and evolution task requires developers to read and understand the code they are going to modify. For this reason, previous research focused on the definition of techniques to automatically assess the readability of a given snippet. However, when many unreadable code sections are detected, developers might be required to manually modify them all to improve their readability. While existing approaches aim at solving specific readability-related issues, such as improving variable names or fixing styling issues, there is still no approach to automatically suggest which actions should be taken to improve code readability. In this paper, we define the first holistic readability-improving approach. As a first contribution, we introduce a methodology for automatically identifying readability-improving commits, and we use it to build a large dataset of 122k commits by mining the whole revision history of all the projects hosted on GitHub between 2015 and 2022. We show that such a methodology has ~86% accuracy. As a second contribution, we train and test the T5 model to emulate what developers did to improve readability. We show that our model achieves a perfect prediction accuracy between 21% and 28%. The results of a manual evaluation we performed on 500 predictions shows that when the model does not change the behavior of the input and it applies changes (34% of the cases), in the large majority of the cases (79.4%) it allows to improve code readability.