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

你的注释过时了吗?迈向自动检测代码与注释一致性

Are your comments outdated? Towards automatically detecting code-comment consistency

Yuan Huang, Yinan Chen, Xiangping Chen, Xiaocong Zhou

AI总结:

本文提出基于学习的 CoCC 方法,通过提取代码与注释变更前后特征及其关系来自动检测过时注释,精确率超过90%,并验证了跨语言适用性和实际项目有效性。

摘要:

在软件开发和维护中,代码注释可以帮助开发者理解源代码,并改善开发者之间的沟通。然而,开发者在修改代码时有时会忽略更新相应的注释,从而产生过时注释(即代码与注释不一致)。过时注释是危险且有害的,可能会误导后续开发者。更严重的是,过时注释在未来某个时候可能导致致命缺陷。为了自动识别源代码中的过时注释,我们提出了一种基于学习的方法,称为 CoCC,用于检测代码与注释之间的一致性。为了高效识别过时注释,我们在代码和注释发生变更前后,从二者中提取多种特征。此外,我们还在模型中考虑了代码与注释之间的关系。实验结果表明,CoCC 能够有效检测过时注释,精确率超过 90%。此外,我们识别出了导致过时注释的 15 个最重要因素,并验证了 CoCC 在不同编程语言中的适用性。我们还使用 CoCC 在开源项目的最新提交中查找过时注释,这进一步证明了所提出方法的有效性。

英文摘要:

In software development and maintenance, code comments can help developers understand source code, and improve communication among developers. However, developers sometimes neglect to update the corresponding comment when changing the code, resulting in outdated comments (i.e., inconsistent codes and comments). Outdated comments are dangerous and harmful and may mislead subsequent developers. More seriously, the outdated comments may lead to a fatal flaw sometime in the future. To automatically identify the outdated comments in source code, we proposed a learning-based method, called CoCC, to detect the consistency between code and comment. To efficiently identify outdated comments, we extract multiple features from both codes and comments before and after they change. Besides, we also consider the relation between code and comment in our model. Experiment results show that CoCC can effectively detect outdated comments with precision over 90%. In addition, we have identified the 15 most important factors that cause outdated comments, and verified the applicability of CoCC in different programming languages. We also used CoCC to find outdated comments in the latest commits of open source projects, which further proves the effectiveness of the proposed method.

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

↑