一句话:重新审视缺陷代码的自然性,发现修复缺陷并不能显著提升代码自然性,基于自然性的缺陷行检测精度极低。
该文重新考察“缺陷代码是否更不自然”以及缺陷修复对源代码自然性的影响。与既有工作不同,作者使用两个大规模、高质量缺陷仓库,并显式排除修复提交中与缺陷无关的改动,从而更准确地比较缺陷行与无缺陷行。评估确认缺陷行通常比无缺陷行更不自然;但修复缺陷后,相关代码行的自然性并未显著提高,修复后的行平均仍与缺陷行同样不自然。因此,缺陷并非源代码不自然性的根本原因,仅依据自然性识别缺陷代码行可能不准确。实验还表明,基于自然性的缺陷行检测精度极低,不足 1%。
Texts in natural languages are highly repetitive and predictable because of the naturalness of natural languages. Recent research validated that source code in programming languages is also repetitive and predictable, and naturalness is an inherent property of source code. It was also reported that buggy code is significantly less natural than bug-free one, and bug fixing substantially improves the naturalness of the involved source code. In this paper, we revisit the naturalness of buggy code and investigate the effect of bug-fixing on the naturalness of source code. Different from the existing investigation, we leverage two large-scale and high-quality bug repositories where bug-irrelevant changes in bug-fixing commits have been explicitly excluded. Our evaluation results confirm that buggy lines are often less natural than bug-free ones. However, fixing bugs could not significantly improve the naturalness of involved code lines. Fixed lines on average are as unnatural as buggy ones. Consequently, bugs are not the root cause of the unnaturalness of source code, and it could be inaccurate to identify buggy code lines solely by the naturalness of source code. Our evaluation results suggest that the naturalness-based buggy line detection results in extremely low precision (less than one percentage).
DOI 原文 ·
@inproceedings{paperbot6991,
title = {Do bugs lead to unnaturalness of source code?},
author = {Yanjie Jiang and Hui Liu and Yuxia Zhang and Weixing Ji and Hao Zhong and Lu Zhang},
booktitle = {FSE},
year = {2022},
doi = {10.1145/3540250.3549149}
}