Source Code评论:代码克隆检测领域被忽视的问题
Source Code Comments: Overlooked in the Realm of Code Clone Detection
摘要:
重用代码可能会在代码存储库中产生重复或近似重复的代码克隆。目前的代码克隆检测技术,如程序依赖图,依赖于代码结构和它们的依赖关系来检测克隆。这些技术是昂贵的,使用大量的处理能力、时间和存储器。在实践中,程序员经常利用代码注释来理解和重用代码,因为注释携带重要的领域知识。但目前的代码检测技术忽略了代码注释,这主要是由于英语语言的歧义性。信息检索技术的最新进展可能具有利用代码注释进行克隆检测的潜力。我们通过在JHotDraw包上实证比较检测克隆的准确性来研究这一点,JHotDraw包包含315个类和27K行代码。为了在文件级别检测克隆,我们使用了一种主题建模技术,潜在狄利克雷分配,来分析代码注释,并使用GRAPLE(利用程序依赖关系图)来分析代码。我们的结果显示94.86召回率和84.21精度与潜在的Dirichlet分配和28.7召回率和55.39精度使用GRAPLE。我们发现潜在狄利克雷分配产生误报的情况下,程序缺乏质量的意见。但是,这种限制可以通过使用混合方法来解决:在文件级别使用代码注释来减少克隆集,然后在方法级别使用基于程序依赖图的技术来检测精确的克隆。我们进一步分析了Java和Python包,Java Swing和PyGUI,发现召回率为74.86%,准确率为84.21%。我们的研究结果要求重新审查的假设,在当前的克隆检测技术中使用的代码注释。
英文摘要:
Reusing code can produce duplicate or near-duplicate code clones in code repositories. Current code clone detection techniques, like Program Dependence Graphs, rely on code structure and their dependencies to detect clones. These techniques are expensive, using large amounts of processing power, time, and memory. In practice, programmers often utilize code comments to comprehend and reuse code, as comments carry important domain knowledge. But current code detection techniques ignore code comments, mainly due to the ambiguity of the English language. Recent advances in information retrieval techniques may have the potential to utilize code comments for clone detection. We investigated this by empirically comparing the accuracy of detecting clones with solely comments versus solely source code (without comments) on the JHotDraw package, which contains 315 classes and 27K lines of code. To detect clones at the file level, we used a topic modeling technique, Latent Dirichlet Allocation, to analyze code comments and GRAPLE -- utilizing Program Dependency Graph -- to analyze code. Our results show 94.86 recall and 84.21 precision with Latent Dirichlet Allocation and 28.7 recall and 55.39 precision using GRAPLE. We found Latent Dirichlet Allocation generated false positives in cases where programs lacked quality comments. But this limitation can be addressed by using a hybrid approach: utilizing code comments at the file level to reduce the clone set and then using Program Dependency Graph-based techniques at the method level to detect precise clones. Our further analysis across Java and Python packages, Java Swing and PyGUI, found a recall of 74.86\% and a precision of 84.21\%. Our findings call for reexamining the assumptions regarding the use of code comments in current clone detection techniques.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。