Background. Code understandability is fundamental. Developers need to clearly understand the code they are modifying. A low understandability can increase the amount of coding effort and misinterpretation of code has impact on the entire development process. Ideally, developers should write clear and understandable code with the least possible effort. Objective. The goal of this work is to investigate if the McCabe Cyclomatic Complexity or the Cognitive Complexity can be a good predictor for the developers' perceived code understandability to understand which of the two complexities can be used as criteria to evaluate if a piece of code is understandable. Method. We designed and conducted an empirical study among 216 junior developers with professional experience ranging from one to four years. We asked them to manually inspect and rate the understandability of 12 Java classes that exhibit different levels of Cyclomatic and Cognitive Complexity. Results. Cognitive Complexity slightly outperforms the Cyclomatic Complexity to predict the developers' perceived understandability. Conclusion. The identification of a clear and validated measure for Code Complexity is still an open issue. Neither the old fashioned McCabe Cyclomatic Complexity and the most recent Cognitive Complexity are good predictors for code understandability, at least when considering the complexity perceived by junior developers.
翻译:代码理解性是根本的。 开发者需要清楚地理解他们正在修改的代码。 低理解性可以增加代码的编码努力量, 错误的代码解释会对整个发展进程产生影响。 理想的是, 开发者应该以尽可能少的努力写出清晰易懂的代码。 目标 。 这项工作的目标是调查McCabe Cyclomatic 复杂度或认知复杂度是否为开发者所认为的代码易理解性的良好预测者,以了解这两种复杂度中的哪一种可以用作评估某一代码是否可理解的标准。 方法 。 我们设计并在216个具有一至四年专业经验的初级开发者中进行了实证研究。 我们要求他们手动检查并评估12个显示不同层次的气候和视觉复杂度的爪哇班的可理解性。 结果 认知性复杂度略高于预测开发者所认为的气候复杂度。 结论 确定明确和验证的代码复杂度衡量标准仍是一个未决问题。 旧的Mcabe Cycloclocality Colliental 考虑最近的复杂度时, 最复杂度并不是最难理解的复杂度。</s>