cyclomatic-complexity

Deriving Cyclomatic Complexity in .NET

感情迁移 提交于 2019-12-01 03:10:34
问题 I know that I can access the cyclomatic complexity to my code in Visual Studio 2008 Team Explorer by right clicking and selecting "Calculate Code Metrics". I would like to expose this data for a web application to display it. Does anybody know of any way of accessing this data through an API? Thanks for your help! 回答1: I use NDepend for stuff like that. You can create CQL queries in NDepend and execute them. Example: SELECT METHODS WHERE CC > 8 returns the methods with a cyclomatic complexity

how could I reduce the cyclomatic complexity?

痴心易碎 提交于 2019-11-30 17:39:38
Whenever I lint a piece of code I'm working on I get the This function's cyclomatic complexity is too high. (7) . But I'm a bit confused on how I could rewrite it in such way so it works. This would be the function that keeps throwing that message: function () { var duration = +new Date() - start.time, isPastHalf = Number(duration) < 250 && Math.abs(delta.x) > 20 || Math.abs(delta.x) > viewport / 2, direction = delta.x < 0; if (!isScrolling) { if (isPastHalf) { if (direction) { this.close(); } else { if (this.content.getBoundingClientRect().left > viewport / 2 && pulled === true) { this.close(

how could I reduce the cyclomatic complexity?

╄→гoц情女王★ 提交于 2019-11-30 01:50:53
问题 Whenever I lint a piece of code I'm working on I get the This function's cyclomatic complexity is too high. (7) . But I'm a bit confused on how I could rewrite it in such way so it works. This would be the function that keeps throwing that message: function () { var duration = +new Date() - start.time, isPastHalf = Number(duration) < 250 && Math.abs(delta.x) > 20 || Math.abs(delta.x) > viewport / 2, direction = delta.x < 0; if (!isScrolling) { if (isPastHalf) { if (direction) { this.close();

How can I reduce the Cyclomatic Complexity of this?

*爱你&永不变心* 提交于 2019-11-29 03:20:31
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. Can't you leverage an object-oriented approach for this? Create an interface that has the doSomething

What is the highest Cyclomatic Complexity of any function you maintain? And how would you go about refactoring it?

萝らか妹 提交于 2019-11-29 02:34:00
问题 I was doing a little exploring of a legacy system I maintain, with NDepend (great tool check it out), the other day. My findings almost made me spray a mouthful of coffee all over my screen. The top 3 functions in this system ranked by descending cyclomatic complexity are: SomeAspNetGridControl.CreateChildControls (CC of 171!!!) SomeFormControl.AddForm (CC of 94) SomeSearchControl.SplitCriteria (CC of 85) I mean 171, wow!!! Shouldn't it be below 20 or something? So this made me wonder. What

How do you calculate cyclomatic complexity for R functions?

假如想象 提交于 2019-11-28 20:42:18
Cyclomatic complexity measures how many possible branches can be taken through a function. Is there an existing function/tool to calculate it for R functions? If not, suggestions are appreciated for the best way to write one. A cheap start towards this would be to count up all the occurences of if , ifelse or switch within your function. To get a real answer though, you need to understand when branches start and end, which is much harder. Maybe some R parsing tools would get us started? Also, I just found a new package called cyclocomp (released 2016). Check it out! You can use codetools:

Do you find cyclomatic complexity a useful measure?

我的梦境 提交于 2019-11-28 16:38:38
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 something I can point to when deciding where to start refactoring. Do you use cyclomatic complexity? What's the

What is Cyclomatic Complexity?

久未见 提交于 2019-11-28 04:16:29
A term that I see every now and then is "Cyclomatic Complexity". Here on SO I saw some Questions about "how to calculate the CC of Language X" or "How do I do Y with the minimum amount of CC", but I'm not sure I really understand what it is. On the NDepend Website , I saw an explanation that basically says "The number of decisions in a method. Each if, for, && etc. adds +1 to the CC "score"). Is that really it? If yes, why is this bad? I can see that one might want to keep the number of if-statements fairly low to keep the code easy to understand, but is this really everything to it? Or is

How can I analyze Python code to identify problematic areas?

孤人 提交于 2019-11-28 02:37:10
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? For measuring cyclomatic complexity, there's a nice tool available at traceback.org . The page also gives a good overview of how to interpret the results. +1

Automatic generation of Unit test cases for .NET and Java [closed]

南楼画角 提交于 2019-11-27 13:12:33
问题 Is there a good tool to generate unit test cases given say a .NET or Java project, it generates unit test cases that would cover an almost 100% code coverage. The number of test cases could be directly proportional to the cyclomatic complexity of the code (the higher the nesting of loops and conditions the higher the cyclomatic complexity) where the higher the cyclomatic complexity, the greater the set of test cases are generated. I'm not expecting it to be fully functional (say I'm going to