当前位置:网站首页>How to monitor code cyclomatic complexity by refactoring indicators
How to monitor code cyclomatic complexity by refactoring indicators
2022-08-04 15:34:00 【InfoQ】
1 引言
2 背景知识
2.1 圈复杂度
2.2 Cyclomatic complexity calculation method
- 顺序结构:The order structure complexity is 1.
- if-else-else、switch-case:每增加一个分支,复杂度增加1,&& 、|| The operation is also a branch.
- 循环结构:Add a loop structure,复杂度增加1.
- return:增加一条return语句,Complexity will increase1.
2.3 Cyclomatic complexity metrics
2.4 Cyclomatic complexity reduction method
- Split into subfunctions
- Each function must have a clear function implementation,Don't merge functional implementations in pursuit of fewer lines
- Logic modules and data modules should be written separately
- Reduce unnecessary conditions、循环分支,尽量少用 if …else … ,Use a ternary expression to replaceif else
- 合并条件表达式,比如使用a || b || c
3 方案概述
3.1 脚本设计
- python
- lizard
- APScheduler
- smtplib
- pymysql
3.2 功能介绍
- C/C++ (works with C++14)
- Java
- C# (C Sharp)
- JavaScript (With ES6 and JSX)
- Python
- Golang
- List the programming languages to analyze.如果留空,All supported languages will be searched.
-l LANGUAGES, --languages LANGUAGES
- 排除与模式匹配的文件.match everything?匹配任何单个字符,“/folder/”Recursively exclude everything in a folder.可以指定多个模式.Don't forget to add around the pattern“”号.
-x EXCLUDE, --exclude EXCLUDE
- 设置白名单, 默认’./whitelizard.txt’
-W WHITELIST, --whitelist WHITELIST
- Threshold for cyclomatic complexity warnings,默认值为15,>15会产生警告.
-C CCN, --CCN CCN
- Sets the limit on the number of fields.number of lines of code,圈复杂度,令牌数,Number of parameters or custom fields.If the function setting exceeds the limit, an alarm will be issued.
-T THRESHOLDS, --Threshold THRESHOLDS
- Output to file according to format
-o OUTPUT_FILE, --output_file OUTPUT_FILE
- 通过BackgroundScheduler创建调度任务,Automatic trigger scan method,result write library
def dojob(): scheduler = BackgroundScheduler() scheduler.add_job(func, "cron", hour=21, minute=30) scheduler.start()
3.3 结果展示
3.3.1 Explanation of report nomenclature
- Cyclomatic complexity,Cyclomatic complexity is also known as branch complexity,最好保持在15 以下,The current script sets the threshold10.
- LOC,The number of lines of code that contain comments,目前设置200阀值.
- Token count ,token的个数,A program can have at most 8192 个令牌, Each token is a word,例如关键字,标识符,常量,标点符号,操作符. Counts parentheses and strings as 1 个令牌. 逗号、句点、LOCAL、分号、END and comments do not count.
- Parameter count,Parameter statistics is the number of parameters of a function,The current script sets the threshold10.
3.3.2 执行结果展示
- Windows环境运行脚本,输入file_root(文件地址)执行扫描,Supports the automatic pop-up of the browser to display the current runningHtml报告
- Execute on a weekly basis,Scan according to the system dimension,Support trigger email notification corresponding to system development to view the method name that exceeds the threshold
3.3.3 Application data monitoring
- Regularly pull the latest code of the specified branch every week,执行文件分析,存储扫描结果,Displayed through data charts
4 总结
边栏推荐
猜你喜欢
洛谷题解P4326 求圆的面积
ITSM软件与工单系统的区别是什么?
实战:10 种实现延迟任务的方法,附代码!
【伸手党福利】投影仪初学者入门——投影亮度及幕布选择——从入门到精通
解决dataset.mnist无法加载进去的情况
基于 Next.js实现在线Excel
界面组件DevExpress ASP.NET Core v22.1 - 增强数据导出功能
remote: Check Access Error, please check your access right or username and password!fatal: Authenti
什么是 DevOps?看这一篇就够了!
In action: 10 ways to implement delayed tasks, with code!
随机推荐
GET 和 POST 请求的区别
Li Mu's deep learning notes are here!
Redis-哨兵模式
SAP ABAP SteamPunk 蒸汽朋克的最新进展 - 嵌入式蒸汽朋克
leetcode: 251. Expanding 2D Vectors
RTC 场景下的屏幕共享优化实践
2022 Hangzhou Electric Multi-School 4
附加:自定义注解(参数校验注解);(写的不好,别看…)
指数族分布与最大熵
实战:10 种实现延迟任务的方法,附代码!
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇
In action: 10 ways to implement delayed tasks, with code!
Http-Sumggling缓存漏洞分析
多线程编程之优先级翻转问题
MySQL优化学习笔记
保证通信的机制有哪些
【北亚数据恢复】IBM System Storage存储lvm信息丢失,卷访问不了的数据恢复方案
如何防止重复下单?
李沐的深度学习笔记来了!
阿尔萨斯监控平台&普罗米修斯监控平台对服务器资源的监控