认知复杂性作为Source Code可理解性测量的实证研究
An Empirical Validation of Cognitive Complexity as a Measure of Source Code Understandability
摘要:
背景:开发人员花费大量时间来理解源代码。静态代码分析工具可以将注意力吸引到开发人员难以理解的代码上。然而,大多数调查结果都是基于未经验证的指标,这可能会导致混乱和代码,难以理解,无法识别。目的:在这项工作中,我们验证了一个度量称为认知复杂性,这是明确设计来衡量代码的可理解性,这是已经被广泛使用,由于其集成在著名的静态代码分析工具。方法:我们进行了系统的文献检索,从测量代码可理解性的研究中获得数据集。通过这种方式,我们获得了427个代码片段的大约24,000个可理解性评估。我们计算了这些测量值与相应指标值的相关性,并通过荟萃分析统计总结了相关系数。结果:认知复杂度与理解时间和理解能力的主观评分呈正相关。该指标显示了与理解任务的正确性和生理措施的相关性的混合结果。结论:这是第一个经过验证的、完全基于代码的度量标准,至少能够反映代码可理解性的某些方面。此外,由于其方法,这项工作表明,代码理解目前以许多不同的方式进行测量,我们也不知道它们是如何相关的。这使得很难比较单个研究的结果,也很难制定一个度量标准来衡量代码理解的各个方面。
英文摘要:
Background: Developers spend a lot of their time on understanding source code. Static code analysis tools can draw attention to code that is difficult for developers to understand. However, most of the findings are based on non-validated metrics, which can lead to confusion and code, that is hard to understand, not being identified. Aims: In this work, we validate a metric called Cognitive Complexity which was explicitly designed to measure code understandability and which is already widely used due to its integration in well-known static code analysis tools. Method: We conducted a systematic literature search to obtain data sets from studies which measured code understandability. This way we obtained about 24,000 understandability evaluations of 427 code snippets. We calculated the correlations of these measurements with the corresponding metric values and statistically summarized the correlation coefficients through a meta-analysis. Results: Cognitive Complexity positively correlates with comprehension time and subjective ratings of understandability. The metric showed mixed results for the correlation with the correctness of comprehension tasks and with physiological measures. Conclusions: It is the first validated and solely code-based metric which is able to reflect at least some aspects of code understandability. Moreover, due to its methodology, this work shows that code understanding is currently measured in many different ways, which we also do not know how they are related. This makes it difficult to compare the results of individual studies as well as to develop a metric that measures code understanding in all its facets.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。