cyclomatic-complexity

How can I reduce the Cyclomatic Complexity of this?

五迷三道 提交于 2020-01-10 01:04:14
问题 I have a method that receives an Object and does something based on what type of object it detects: void receive(Object object) { if (object instanceof ObjectTypeA) { doSomethingA(); } else { if (object instanceof ObjectTypeB) { doSomethingB(); } else { if (object instanceof ObjectTypeC) { doSomethingC(); } else { if (object instanceof ObjectTypeD) { doSomethingD(); } else { // etc... } } } } } How can I reduce the Cyclomatic Complexity? I searched around but couldn't find anything too useful

Code Metrics Calculation in Visual Studio

点点圈 提交于 2019-12-31 08:07:03
问题 What is the prefered score range for the code metrics calculation for the following Maintainability Index Cyclomatic Complexity Depth of Inheritance class Coupling 回答1: The theoretically optimal values are: Maintainability index: 100. Higher values indicate better maintainability. Cyclomatic complexity: 1. The number of different paths that code can take. Depth of inheritance: 1. The number of class definitions above this one in the inheritance tree, not including interfaces. Class coupling:

Code Metrics Calculation in Visual Studio

早过忘川 提交于 2019-12-31 08:06:07
问题 What is the prefered score range for the code metrics calculation for the following Maintainability Index Cyclomatic Complexity Depth of Inheritance class Coupling 回答1: The theoretically optimal values are: Maintainability index: 100. Higher values indicate better maintainability. Cyclomatic complexity: 1. The number of different paths that code can take. Depth of inheritance: 1. The number of class definitions above this one in the inheritance tree, not including interfaces. Class coupling:

custom threshold for CA1502 in visual studio 2013 ultimate

匆匆过客 提交于 2019-12-24 02:59:05
问题 This question: Custom threshold for CA1502 discusses how to set up custom thresholds for code metrics rules in code analysis. I have the same problem, but think that the old question is out of date. To repeat: In particular, we would like our Build to fail when a method has a code complexity of more than 20. Unfortunately, rule CA1502 has a threshold of 25: The rule reports a violation when the cyclomatic complexity is more than 25. Can we somehow change this? The accepted answer is to edit

Is there a limit to how many levels you can nest in JavaScript?

大憨熊 提交于 2019-12-24 01:51:26
问题 Say you have this really complex algorithm that requires dozens of for loops. Does JavaScript have a limit to how deep loops can be nested or is there no limit? What is the best practice for deep nested for loops? I tried searching on MDN but couldn't find what I was looking for Edit I'm looking if there is a built in limit. For example if you had something like this If ( a = 1, a < 3, a++) { if (b = 1; b < 3; b++) { ... if (cd = 1; cd < 3; cd++) Would this actually be possible or would JS

How to calculate cyclomatic complexity of a Clojure function?

ぃ、小莉子 提交于 2019-12-24 00:18:49
问题 What would be a reasonable way to calculate the cyclomatic complexity of a Clojure function? It's easy to count decision points based on functions like 'if' and 'cond', but it starts to get tricky with macros. Anyone has tried this for Clojure or maybe another functional language? 回答1: Macros are an abstraction and should not contributed to the CC calculation, any more than a function call would. That said, I don't think that CC is particularly interesting for Clojure. I would be more

How to improve Cyclomatic Complexity?

白昼怎懂夜的黑 提交于 2019-12-21 03:59:24
问题 Cyclomatic Complexity will be high for methods with a high number of decision statements including if/while/for statements. So how do we improve on it? I am handling a big project where I am supposed to reduced the CC for methods that have CC > 10. And there are many methods with this problem. Below I will list down some eg of code patterns (not the actual code) with the problems I have encountered. Is it possible that they can be simplified? Example of cases resulting in many decision

Clarifying the manual count of Cyclomatic Complexity

淺唱寂寞╮ 提交于 2019-12-20 03:05:23
问题 Let's assume that we have a code like this: switch(y) { case 1: case 2: case 3: function(); break; case 4: case 5: case 6: function_2(); break; } Can we get the CC value as 6+1 here? Why a value of 1 is added? If the CC value is considered as 7, is that the number of independent paths? What if a fall through scenario is considered above? As only possible two unique paths are there, 2 +1 =3 Which of the above are correct or are the both of them correct? 回答1: As we know, CC = P+1. Here, P =

How does a static Dictionary have cyclomatic complexity?

和自甴很熟 提交于 2019-12-19 03:52:04
问题 I have the following class: public static class MyClass { private static readonly Dictionary<Type, Func<string, object>> valueTypes; static MyClass() { var dictionary = new Dictionary<Type, Func<string, object>>(); dictionary.Add(typeof(bool), x => bool.Parse(x)); dictionary.Add(typeof(byte), x => byte.Parse(x)); dictionary.Add(typeof(char), x => char.Parse(x)); dictionary.Add(typeof(decimal), x => decimal.Parse(x)); dictionary.Add(typeof(double), x => double.Parse(x)); dictionary.Add(typeof

Seeking clarifications about structuring code to reduce cyclomatic complexity

。_饼干妹妹 提交于 2019-12-18 11:22:08
问题 Recently our company has started measuring the cyclomatic complexity (CC) of the functions in our code on a weekly basis, and reporting which functions have improved or worsened. So we have started paying a lot more attention to the CC of functions. I've read that CC could be informally calculated as 1 + the number of decision points in a function (e.g. if statement, for loop, select etc), or also the number of paths through a function... I understand that the easiest way of reducing CC is to