没有合适的资源?快使用搜索试试~ 我知道了~
sonarsource认知复杂度文档CognitiveComplexity.pdf
需积分: 20 0 下载量 69 浏览量
2021-12-30
18:18:54
上传
评论
收藏 548KB PDF 举报
温馨提示
试读
21页
sonarsource认知复杂度文档
资源推荐
资源详情
资源评论
A new way of measuring understandability
Copyright SonarSource S.A. 2016 - 2021, Switzerland. All content is copyright protected.
By G. Ann Cam
pbell, SonarSour
ce SA
COGNITIVE
COMPLEXITY
Copyright SonarSource S.A., 2021, Switzerland. All content is copyright protected.
5 April 2021, Version 1.5
Abstract
Cyclomatic Complexity was initially formulated as a measurement of the “testability and
maintainability” of the control flow of a module. While it excels at measuring the former, its
underlying mathematical model is unsatisfactory at producing a value that measures the
latter. This white paper describes a new metric that breaks from the use of mathematical
models to evalua
te code in order to remedy Cyclomatic Complexity’s shortcomings and
produce a measurement that more accurately reflects the relative difficulty of understanding,
and therefore of maintaining methods, classes, and applications.
A note on terminology
While Cognitive Complexity is a language-neutral metric that applies equally to files and
classes, and to methods, procedures, functions, and so on, the Object-O
riented terms
“class” and “method” are used for convenience.
Copyright SonarSource S.A., 2016-2021, Switzerland. All content is copyright protected.
- 1 -
Cognitive Complexity - a new way of measuring understandability
Copyright SonarSource S.A. 2016 - 2021, Switzerland. All content is copyright protected.
Copyright SonarSource S.A., 2021, Switzerland. All content is copyright protected.
Table of Contents
Introduction 3
An illustration of the problem 4
Basic criteria and methodology 4
Ignore shorthand 5
Increment for breaks in the linear flow 5
Catches 6
Switches 6
Sequences of logical operators 6
Recursion 7
Jumps to labels 7
Increment for nested flow-break structures 7
The implications 9
Conclusion 10
References 10
Appendix A: Compensating Usages 11
Appendix B: Specification 14
Appendix C: Examples 16
Change log 2
0
Copyright SonarSource S.A., 2016-2021, Switzerland. All content is copyright protected.
- 2 -
Cognitive Complexity - a new way of measuring understandability
3
Copyright SonarSource S.A. 2016 - 2021, Switzerland. All content is copyright protected.
Copyright SonarSource S.A., 2021, Switzerland. All content is copyright protected.
Introduction
Thomas J. McCabe’s Cyclomatic Complexity has long been the de facto standard for
measuring the complexity of a method’s control flow. It was originally intended “to identify
software modules that will be difficult to test or maintain”[1], but while it accurately calculates
the minimum number of test cases required to fully cover a method, it is not a satisfactory
measure of understandability.
This is because methods with equal Cyclomatic Complexity do
not necessarily present equal difficulty to the maintainer, leading to a sense that the
measurement “cries wolf” by over-valuing some structures, while under-valuing others.
At the same time, Cyclomatic Complexity is no longer comprehensive. Formulated in a
Fortran environment in 1976, it doesn’t include modern language structures like try/catch,
an
d lambdas.
And finally, because each method has a minimum Cyclomatic Complexity score of one, it is
impossible to know whether any given class with a high aggregate Cyclomatic Complexity is
a large, easily maintained domain class, or a small class with a complex control flow. Beyond
the class level, it is widely acknowledged that the Cyclomatic Complexity scores of
applications correlate to their lines of
code totals. In other words, Cyclomatic Complexity is of
little use above the method level.
As a remedy for these problems, Cognitive Complexity has been formulated to address
modern language structures, and to produce values that are meaningful at the class and
application levels. More importantly, it departs from the practice of evaluating code based on
mathematical models so that it can yield assessment
s of control flow that correspond to
programmers’ intuitions about the mental, or cognitive effort required to understand those
flows.
Copyright SonarSource S.A., 2016-2021, Switzerland. All content is copyright protected.
- 3 -
Cognitive Complexity - a new way of measuring understandability
4
Copyright SonarSource S.A. 2016 - 2021, Switzerland. All content is copyright protected.
剩余20页未读,继续阅读
资源评论
一线大码
- 粉丝: 1344
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 批量将py编译为pyd文件.atbx
- Python项目-学生管理系统
- verilog HDL硬件语法设计包括算术运算三人表决器Verilog的阻塞和非阻塞赋值源码例程quartus13.1工程合集
- 【文章话题分类论文】OpenAlex Topic Classification Whitepaper
- linux学习常用命令
- 功率拓扑快速参考指南-ti,TI官方出品
- 开关电源拓朴图表,各种电路拓扑表格
- 登录和注册 前端:vue3+iview plus +axios 后台:spring boot +mybatis
- 软件测试入门简介:从基础到实践的全面介绍
- 2024CDA Level Ⅰ 认证考试大纲
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功