cyclomatic-complexity

Do you find cyclomatic complexity a useful measure?

大兔子大兔子 提交于 2019-11-27 09:50:57
问题 I've been playing around with measuring the cyclomatic complexity of a big code base. Cyclomatic complexity is the number of linearly independent paths through a program's source code and there are lots of free tools for your language of choice. The results are interesting but not surprising. That is, the parts I know to be the hairiest were in fact the most complex (with a rating of > 50). But what I am finding useful is that a concrete "badness" number is assigned to each method as

Cyclomatic complexity of IF((A>B) AND (C>D)) and IF((A>B) OR (C>D))

时光总嘲笑我的痴心妄想 提交于 2019-11-27 07:11:01
问题 I want to know the cyclomatic complexity of two section of code, IF((A>B) AND (C>D)) { a=a+b;c=c+d;} as far my knowledge the cyclomatic complexity of above code=2+1=3, Another code IF((A>B) OR (C>D)) {a=a+b;c=c+d;} Complexity of the above code is=4+1=5, whether the above complexities are correct or not? 回答1: Both complexities are same and equal 3, counted in 4 ways. I agree with Neil on using De Morgan proving that they are same, I think same can be seen from graphs where it matters for

In a switch vs dictionary for a value of Func, which is faster and why?

这一生的挚爱 提交于 2019-11-27 06:57:39
Suppose there is the following code: private static int DoSwitch(string arg) { switch (arg) { case "a": return 0; case "b": return 1; case "c": return 2; case "d": return 3; } return -1; } private static Dictionary<string, Func<int>> dict = new Dictionary<string, Func<int>> { {"a", () => 0 }, {"b", () => 1 }, {"c", () => 2 }, {"d", () => 3 }, }; private static int DoDictionary(string arg) { return dict[arg](); } By iterating over both methods and comparing, I am getting that the dictionary is slightly faster, even when "a", "b", "c", "d" is expanded to include more keys. Why is this so? Does

How can I analyze Python code to identify problematic areas?

本小妞迷上赌 提交于 2019-11-26 23:46:11
问题 I have a large source repository split across multiple projects. I would like to produce a report about the health of the source code, identifying problem areas that need to be addressed. Specifically, I'd like to call out routines with a high cyclomatic complexity, identify repetition, and perhaps run some lint-like static analysis to spot suspicious (and thus likely erroneous) constructs. How might I go about constructing such a report? 回答1: For measuring cyclomatic complexity, there's a

Conditional logging with minimal cyclomatic complexity

痴心易碎 提交于 2019-11-26 19:30:37
After reading " What’s your/a good limit for cyclomatic complexity? ", I realize many of my colleagues were quite annoyed with this new QA policy on our project: no more 10 cyclomatic complexity per function. Meaning: no more than 10 'if', 'else', 'try', 'catch' and other code workflow branching statement. Right. As I explained in ' Do you test private method? ', such a policy has many good side-effects. But: At the beginning of our (200 people - 7 years long) project, we were happily logging (and no, we can not easily delegate that to some kind of ' Aspect-oriented programming ' approach for

Conditional logging with minimal cyclomatic complexity

喜欢而已 提交于 2019-11-26 12:17:06
问题 After reading \"What’s your/a good limit for cyclomatic complexity?\", I realize many of my colleagues were quite annoyed with this new QA policy on our project: no more 10 cyclomatic complexity per function. Meaning: no more than 10 \'if\', \'else\', \'try\', \'catch\' and other code workflow branching statement. Right. As I explained in \'Do you test private method?\', such a policy has many good side-effects. But: At the beginning of our (200 people - 7 years long) project, we were happily

In a switch vs dictionary for a value of Func, which is faster and why?

ⅰ亾dé卋堺 提交于 2019-11-26 12:13:11
问题 Suppose there is the following code: private static int DoSwitch(string arg) { switch (arg) { case \"a\": return 0; case \"b\": return 1; case \"c\": return 2; case \"d\": return 3; } return -1; } private static Dictionary<string, Func<int>> dict = new Dictionary<string, Func<int>> { {\"a\", () => 0 }, {\"b\", () => 1 }, {\"c\", () => 2 }, {\"d\", () => 3 }, }; private static int DoDictionary(string arg) { return dict[arg](); } By iterating over both methods and comparing, I am getting that