arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 1506.01159cs.SE
收藏

论bug代码的“自然性”

On the "Naturalness" of Buggy Code

Baishakhi Ray, Vincent Hellendoorn, Saheel Godhane, Zhaopeng Tu, Alberto Bacchelli, Premkumar Devanbu

摘要:

真正的软件,即由kingdom开发的程序员解决现实世界问题的软件,往往是“自然的”,就像语音或自然语言一样;它往往是高度重复和可预测的。研究人员已经通过统计模型捕捉到了软件的这种自然性,并将其用于建议引擎、移植工具、编码标准检查器和习惯用法挖掘器中。这表明,对于一个好的统计语言模型来说,看起来不太可能或令人惊讶的代码在某种意义上是“不自然的”,因此可能是可疑的。在本文中,我们调查这一假设。我们考虑了一个大型的bug修复提交语料库(约。8,296),来自10个不同的Java项目,我们专注于它的语言统计,评估错误代码的自然性和相应的修复。我们发现,有bug的代码往往更具熵(即,不自然的),随着bug的修复而变得不那么自然。专注于高熵行在成本效益方面与一些众所周知的静态错误发现器(PMD,FindBugs)相似,并且使用熵度量对这些错误发现器的警告进行排序可以提高检查警告中涉及的代码的成本效益。这表明熵可能是一种有效的独立于语言的简单方法,可以补充PMD或FindBugs的有效性,并且基于搜索的错误修复方法可以从使用熵进行错误定位和搜索修复中受益。

英文摘要:

Real software, the kind working programmers produce by the kLOC to solve real-world problems, tends to be "natural", like speech or natural language; it tends to be highly repetitive and predictable. Researchers have captured this naturalness of software through statistical models and used them to good effect in suggestion engines, porting tools, coding standards checkers, and idiom miners. This suggests that code that appears improbable, or surprising, to a good statistical language model is "unnatural" in some sense, and thus possibly suspicious. In this paper, we investigate this hypothesis. We consider a large corpus of bug fix commits (ca.~8,296), from 10 different Java projects, and we focus on its language statistics, evaluating the naturalness of buggy code and the corresponding fixes. We find that code with bugs tends to be more entropic (i.e., unnatural), becoming less so as bugs are fixed. Focusing on highly entropic lines is similar in cost-effectiveness to some well-known static bug finders (PMD, FindBugs) and ordering warnings from these bug finders using an entropy measure improves the cost-effectiveness of inspecting code implicated in warnings. This suggests that entropy may be a valid language-independent and simple way to complement the effectiveness of PMD or FindBugs, and that search-based bug-fixing methods may benefit from using entropy both for fault-localization and searching for fixes.

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

↑