OCLint的部分规则(Size 部分)

2024-06-21 04:18
文章标签 规则 部分 size oclint

本文主要是介绍OCLint的部分规则(Size 部分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

OCLint的部分规则(Size 部分)

对OCLint的部分规则进行简单翻译解释,有部分进行了验证以及进一步分析、测试。OCLint其他相关内容如下:

--
OCLint-iOS-OC项目几种简单使用OCLint的部分规则(Basic 部分)
OCLint的部分规则(Unuseed 部分)OCLint的部分规则(Size 部分)
OCLint的部分规则(Redundant 部分)OCLint的部分规则(Naming 部分)
OCLint的部分规则(Migration 部分)OCLint的部分规则(Empty 部分)
OCLint的部分规则(Design 部分)OCLint的部分规则(Convention 部分)
OCLint的部分规则(CoCoa 部分)



1、high cyclomatic complexity

      Since:0.4 定义类传送门~点击

Cyclomatic complexity is determined by the number of linearly independent paths through a program’s source code. In other words, cyclomatic complexity of a method is measured by the number of decision points, like if, while, and for statements, plus one for the method entry.

简单解释:圈复杂度过高。统计一个函数有多少个分支(if, while,for,等等),没有的话复杂度为一,每增加一个分支复杂度加一。简单计算的话V(G)=e-n+2。其中,e表示控制流图中边的数量,n表示控制流图中节点的数量,或者V(G)=区域数=判定节点数+1。当然可以数一数。

    void example(int a, int b, int c) { // 1if (a == b) {                   // 2if (b == c) {               // 3 } else if (a == c){          // 3}else {}}for (int i = 0; i < c; i++)  {  // 4}switch(c)  {case 1:                   // 5break;case 2:                   // 6break;default:                  // 7break;}}

Thresholds:
CYCLOMATIC_COMPLEXITY The cyclomatic complexity reporting threshold, default value is 10. Suppress:

Suppress:
__attribute__((annotate("oclint:suppress[high cyclomatic complexity]")))

References:
McCabe (December 1976). “A Complexity Measure”. IEEE Transactions on Software Engineering: 308–320

2、long class

      Since:0.6 定义类传送门~点击

Long class generally indicates that this class tries to do many things. Each class should do one thing and that one thing well.

简单解释:类行数太多。

    class Foo {void bar() {// 1001 lines of code}}

Thresholds:
LONG_CLASS The class size reporting threshold, default value is 1000.

3、 long line

      Since:0.6 定义类传送门~点击

When the number of characters for one line of code is very high, it largely harms the readability. Break long lines of code into multiple lines.

简单解释:单行代码太长,影响可读性。

    void example(){int a012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;}

Thresholds:
LONG_LINE The long line reporting threshold, default value is 100.

4、long method

      Since:0.6 定义类传送门~点击

Long method generally indicates that this method tries to do many things. Each method should do one thing and that one thing well.

简单解释:方法太长,影响阅读,应该实现单一职责。

    void example() {cout << "hello world";cout << "hello world";// repeat 48 times}

Thresholds:
LONG_METHOD The long method reporting threshold, default value is 50.

5、 high ncss method

      Since:0.6 定义类传送门~点击

This rule counts number of lines for a method by counting Non Commenting Source Statements (NCSS). NCSS only takes actual statements into consideration, in other words, ignores empty statements, empty blocks, closing brackets or semicolons after closing brackets. Meanwhile, a statement that is broken into multiple lines contribute only one count.

简单解释:其实是指某个代码块中代码行数过多(只统计有效的语句),查看代码块中代码是否能拆分,公共功能能否提供一个公共接口。空语句,空块,右括号或分号后的右括号会被忽略。

    void example()          // 1{if (1)              // 2{}  else                // 3{}}

Thresholds:
NCSS_METHOD The high NCSS method reporting threshold, default value is 30.

Suppress:
attribute((annotate(“oclint:suppress[high ncss method]”)))

6、deep nested block

      Since:0.6 定义类传送门~点击

This rule indicates blocks nested more deeply than the upper limit.

简单解释:嵌套块是否超过指定的深度值.

    if (1) {               // 1{           // 2{       // 3}}}

Thresholds:
NESTED_BLOCK_DEPTH The depth of a block or compound statement reporting threshold, default value is 5.

7、high npath complexity

      Since:0.4 定义类传送门~点击

NPath complexity is determined by the number of execution paths through that method. Compared to cyclomatic complexity, NPath complexity has two outstanding characteristics: first, it distinguishes between different kinds of control flow structures; second, it takes the various type of acyclic paths in a flow graph into consideration.
Based on studies done by the original author in AT&T Bell Lab, an NPath threshold value of 200 has been established for a method.

简单解释:NPath复杂度是一个方法中各种可能的执行路径总和,一般把200作为考虑降低复杂度的临界点,这里提示NPath复杂度过高。

    void example() {// complicated code that is hard to understand}

Thresholds:
NPATH_COMPLEXITY The NPath complexity reporting threshold, default value is 200.

Suppress:
__attribute__((annotate("oclint:suppress[high npath complexity]")))

References:
Brian A. Nejmeh (1988). “NPATH: a measure of execution path complexity and its applications”. Communications of the ACM 31 (2) p. 188-200

8、too many fields

      Since:0.7 定义类传送门~点击

A class with too many fields indicates it does too many things and lacks proper abstraction. It can be redesigned to have fewer fields.

简单解释:一个类中有定义太多东西,需要进行适当的抽象、设计。

    class c {int a, b;int c;// ...int l;int m, n;// ...int x, y, z;void m() {}};

Thresholds:
TOO_MANY_FIELDS The reporting threshold for too many fields, default value is 20.

9、too many methods

      Since:0.7 定义类传送门~点击

A class with too many methods indicates it does too many things and is hard to read and understand. It usually contains complicated code, and should be refactored.

简单解释:一个类有太多的方法,证明他做了太多的事儿,不利于理解。应该考虑重构。考虑单一职责。

    class c {int a();int b();int c();// ...int l();int m();int n();// ...int x();int y();int z();int aa();int ab();int ac();int ad();int ae();};
10、too many parameters

      Since:0.7 定义类传送门~点击

Methods with too many parameters are hard to understand and maintain, and are thirsty for refactorings, like Replace Parameter With method, Introduce Parameter Object, or Preserve Whole Object.

简单解释: 一个方法中参数过多。

    void example(int a, int b, int c, int d, int e, int f,int g, int h, int i, int j, int k, int l) {}

TOO_MANY_PARAMETERS The reporting threshold for too many parameters, default value is 10.

References:
Fowler, Martin (1999). Refactoring: Improving the design of existing code. Addison Wesley.

这篇关于OCLint的部分规则(Size 部分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1080177

相关文章

python中os.stat().st_size、os.path.getsize()获取文件大小

《python中os.stat().st_size、os.path.getsize()获取文件大小》本文介绍了使用os.stat()和os.path.getsize()函数获取文件大小,文中通过示例代... 目录一、os.stat().st_size二、os.path.getsize()三、函数封装一、os

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

Adblock Plus官方规则Easylist China说明与反馈贴(2015.12.15)

-------------------------------特别说明--------------------------------------- 视频广告问题:因Adblock Plus的局限,存在以下现象,优酷、搜狐、17173黑屏并倒数;乐视、爱奇艺播放广告。因为这些视频网站的Flash播放器被植入了检测代码,而Adblock Plus无法修改播放器。 如需同时使用ads

项目实战系列三: 家居购项目 第四部分

购物车 🌳购物车🍆显示购物车🍆更改商品数量🍆清空购物车&&删除商品 🌳生成订单 🌳购物车 需求分析 1.会员登陆后, 可以添加家居到购物车 2.完成购物车的设计和实现 3.每添加一个家居,购物车的数量+1, 并显示 程序框架图 1.新建src/com/zzw/furns/entity/CartItem.java, CartItem-家居项模型 /***

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

关于断言的部分用法

1、带变量的断言  systemVerilog assertion 中variable delay的使用,##[variable],带变量的延时(可变延时)_assertion中的延时-CSDN博客 2、until 的使用 systemVerilog assertion 中until的使用_verilog until-CSDN博客 3、throughout的使用   常用于断言和假设中的

牛客小白月赛100部分题解

比赛地址:牛客小白月赛100_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ A.ACM中的A题 #include<bits/stdc++.h>using namespace std;#define ll long long#define ull = unsigned long longvoid solve() {ll a,b,c;cin>>a>>b>

VB和51单片机串口通信讲解(只针对VB部分)

标记:该篇文章全部搬自如下网址:http://www.crystalradio.cn/thread-321839-1-1.html,谢谢啦            里面关于中文接收的部分,大家可以好好学习下,题主也在研究中................... Commport;设置或返回串口号。 SettingS:以字符串的形式设置或返回串口通信参数。 Portopen:设置或返回串口

关联规则(一)Apriori算法

此篇文章转自 http://blog.sina.com.cn/s/blog_6a17628d0100v83b.html 个人觉得比课本上讲的更通俗易懂! 1.  挖掘关联规则 1.1   什么是关联规则 一言蔽之,关联规则是形如X→Y的蕴涵式,表示通过X可以推导“得到”Y,其中X和Y分别称为关联规则的先导(antecedent或left-hand-side, LHS)和后