问题标签 [cyclomatic-complexity]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
27527 浏览

c - 以下过程的控制流程图和圈复杂度

我必须找到这段代码的圈复杂度,然后提出一些白盒测试用例和黑盒测试用例。但是我在为代码制作 CFG 时遇到了麻烦。

也希望对测试用例有一些帮助。

0 投票
4 回答
394 浏览

c - C函数只调用一次和圈复杂度

我认为这个问题更多的是关于风格:我有一个算法,它的 CC 非常高(还有很多行!)。我想减少它,这很容易,因为有一些可以分组的代码。问题是,以这种方式做事我会有一个“大”函数调用“小”函数,这些函数只被调用一次。

在我看来,尽管函数被调用一次,但将一个大函数分成小块更利于代码的易读性(在这种情况下)。

你怎么看?类似情况你怎么办?

0 投票
2 回答
6830 浏览

java - Annotations for enforcing cyclomatic complexity and LCOM constrains

At work we are using several tools to capture several metrics (mostly cyclomatic complexity and LCOM). We use those to get warning flags and to guide pre-emptive refactoring efforts. It's been very beneficial in increasing code quality.

However, the process is not tied to the build process. It is conducted separately. Moreover, I'm looking for something that can be made intrinsic to the source code (as opposed to an external process ran on it.)

Is anyone aware of a group of annotations and configurable annotation processor(s) that can be run from the compiler, and which will make the build fail if code doesn't comply with threshold cyclomatic/LCOM metrics?

I guess I could run ckjm, checkstyle and pmd from maven/ant, BUT some work on source code, and others work on bytecode. It would be nice to have one consolidated tool that works on the source code before compilation begins.

The other thing is that it'd be nice if there are sets of annotations that could drive this (to allow customization that will be inevitably be needed for corner cases.)

Then, when we run the tool, by default applies strict (and configurable) metric threshold except on those artifacts that are annotated with (hopefully documented and legitimate) more relaxed thresholds. For some methods that cannot/should not be reduced, a relaxed cyclomatic complexity makes sense. For plain POJOs w/o behavior, LCOMs need to be relaxed... and so forth and so forth.

Looking and googling as I might, I have not been able to find anything (hopefully open source). But I might as well ask here just in case anyone is aware of anything of the sort.

Thanks.

0 投票
12 回答
22213 浏览

sql - 衡量 SQL 语句的复杂性

大多数编程语言中方法的复杂性可以用静态源代码分析器以圈复杂度来衡量。是否有类似的度量标准来衡量 SQL 查询的复杂性?

测量查询返回所需的时间很简单,但如果我只想能够量化查询的复杂程度怎么办?

[编辑/注释] 虽然获取执行计划很有用,但在这种情况下,这不一定是我想要确定的。我不是在寻找服务器执行查询的难度,我在寻找一个指标来确定开发人员编写查询的难度以及包含缺陷的可能性有多大。

[编辑/注释 2] 诚然,有时测量复杂性没有用,但也有有时有用。有关该主题的进一步讨论,请参阅此问题

0 投票
1 回答
1118 浏览

model - 使用 Automapper 将大域模型映射到数据库对象

我想使用 Automapper 将我的模型对象映射到数据库对象。假设数据库对象有 30 多个字段,我想从我的模型中映射 20 个属性中的 10 个。为了使它更复杂,我需要在更新记录时映射不同的属性,而不是在将新记录插入数据库时​​映射。

我正在使用的解决方案是创建 2 个通用类 Insert 和 Update 以及指定这两个映射的映射配置文件。

下面的例子:

然而,随着圈复杂度进入天空(超过 50 个),映射变得令人讨厌,因为我需要为我未映射的所有属性定义 Ignore():

我通过创建新对象解决了插入新记录的问题:

但它不适用于我想将属性映射到现有对象而不是新实例的更新:

我宁愿避免 DynamicMap() 保持对映射的完全控制(所以我不会错误地映射随机属性)。我的目标是解决圈复杂度问题。请不要建议使用 ValueInjecter 或任何其他方法。我正在 AutoMapper 中寻找解决方案。

0 投票
1 回答
965 浏览

c# - 为什么使用 lambda 进行列表初始化会导致高圈复杂度?

使用 lambda 初始化列表会导致高 IL 圈复杂性:为什么以及如何消除这种复杂性?例如以下代码导致类的静态构造函数(实际上是编译器生成的)非常复杂:1 + 列表计数。

注意:复杂度是用计算的NDepend

0 投票
4 回答
20517 浏览

c# - 如何提高圈复杂度?

对于具有大量决策语句(包括 if/while/for 语句)的方法,循环复杂度会很高。那么我们如何改进它呢?

我正在处理一个大型项目,我应该减少 CC > 10 的方法的 CC。并且有很多方法可以解决这个问题。下面我将列出一些我遇到的问题的代码模式(不是实际代码)。是否可以简化它们?

导致许多决策声明的案例示例:

情况1)

案例2)

案例 3)

0 投票
1 回答
775 浏览

delphi - 圈复杂度 - Delphi API

我正在寻找 Delphi (2010) 中的 Cyclomatic Complexity Api。我需要创建一个程序来分析源代码并报告所有类中所有方法的循环复杂度(就像 SourceMonitor 一样)。
我不能使用其他软件,我真的需要构建一个。
有谁知道 Delphi 2010 的 API 可以做到这一点?

0 投票
1 回答
919 浏览

clojure - 如何计算 Clojure 函数的圈复杂度?

计算 Clojure 函数的圈复杂度的合理方法是什么?根据“if”和“cond”等函数计算决策点很容易,但使用宏开始变得棘手。有人尝试过 Clojure 或其他函数式语言吗?

0 投票
6 回答
1038 浏览

private - 通过使用私有方法正确地降低了圈复杂度?

使用私有方法通过将一些决策点重构为单独的方法来降低 CC 会降低实际方法的 CC 并易于阅读,但不会减少在测试中获得完整分支覆盖的工作量。

这合理吗?你有什么现场经验?