cyclomatic-complexity

How do you calculate cyclomatic complexity for R functions?

烈酒焚心 提交于 2019-12-17 22:50:03
问题 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? 回答1:

What is Cyclomatic Complexity?

二次信任 提交于 2019-12-17 17:38:07
问题 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

Reducing the cyclomatic complexity, multiple if statements

a 夏天 提交于 2019-12-11 10:33:38
问题 I have the following code: private Facility updateFacility(Facility newFacility, Facility oldFacility) { if (newFacility.getCity() != null) oldFacility.setCity(newFacility.getCity()); if (newFacility.getContactEmail() != null) oldFacility.setContactEmail(newFacility.getContactEmail()); if (newFacility.getContactFax() != null) oldFacility.setContactFax(newFacility.getContactFax()); if (newFacility.getContactName() != null) oldFacility.setContactName(newFacility.getContactName()); // ...... }

Tools to automate calculation of cyclomatic complexity in java?

做~自己de王妃 提交于 2019-12-10 12:57:33
问题 Are there any tools available for Java that can automagically determine the cyclomatic complexity of given Java code? I have sought out tools online, and have yet to find one. 回答1: I use Sonar (my preferred method). There are plugins to "automagically" generate the report at build time (i.e. ANT/Maven, etc...). Another related post on how to show the CC on the dashboard: how to list methods with most cyclomatic complexity One other tool I've used in the past is corbetura. You have to have

How can the cyclomatic complexity be 27 in a method with 13 event handler subscriptions?

落爺英雄遲暮 提交于 2019-12-09 16:52:12
问题 We have this code, sortof: private void InitializeEvents() { this.Event1 += (s,e) => { }; this.Event2 += (s,e) => { }; this.Event3 += (s,e) => { }; this.Event4 += (s,e) => { }; this.Event5 += (s,e) => { }; this.Event6 += (s,e) => { }; this.Event7 += (s,e) => { }; this.Event8 += (s,e) => { }; this.Event9 += (s,e) => { }; this.Event10 += (s,e) => { }; this.Event11 += (s,e) => { }; this.Event12 += (s,e) => { }; this.Event13 += (s,e) => { }; } Code analysis in VS10 Ultimate says "cyclomatic

Cyclomatic complexity using jar files

£可爱£侵袭症+ 提交于 2019-12-08 11:00:21
问题 I am working on a project which requires me to find the cyclomatic complexity of Apache ant (Versions 1.1 through 1.6). I have been asked to use the jar files for this purpose. I used a couple of tools (Xdepend trial version and Cyvis ) to have a look at the results. Then i tried to validate the results with results from the source code of Ant Ver1.6. For analyzing the source i used a Netbeans plugin and also manaully found the CC of some methods. What i found was that in many cases the CC

How do I find cycles in my object hierarchy?

江枫思渺然 提交于 2019-12-06 05:38:50
问题 There is a class Company , which has reference to another instance of Company to represent the parent . Lets say there are four companies c1 , c2 , c3 & c4 and c2 , c3 , c4 has parent company set as c1 . For example: public class Company { public Company parent; public Company() { } public Company(Company parent) { this.parent = parent; } public static void main(String[] args) { Company c1 = new Company(); Company c2 = new Company(c1); Company c3 = new Company(c1); Company c4 = new Company(c1

Cyclomatic Complexity in piece of code with multiple exit points

非 Y 不嫁゛ 提交于 2019-12-04 14:04:49
问题 I have this method that validates a password: /** * Checks if the given password is valid. * * @param password The password to validate. * @return {@code true} if the password is valid, {@code false} otherwise. */ public static boolean validatePassword(String password) { int len = password.length(); if (len < 8 || len > 20) return false; boolean hasLetters = false; boolean hasDigits = false; for (int i=0; i<len; i++) { if (!Character.isLetterOrDigit(password.charAt(i))) return false;

How do I find cycles in my object hierarchy?

佐手、 提交于 2019-12-04 10:16:44
There is a class Company , which has reference to another instance of Company to represent the parent . Lets say there are four companies c1 , c2 , c3 & c4 and c2 , c3 , c4 has parent company set as c1 . For example: public class Company { public Company parent; public Company() { } public Company(Company parent) { this.parent = parent; } public static void main(String[] args) { Company c1 = new Company(); Company c2 = new Company(c1); Company c3 = new Company(c1); Company c4 = new Company(c1); } If we set c2 as parent company of the c1 : c1.parent = c2; then it will create a Cyclomatic

Measuring the complexity of SQL statements

一个人想着一个人 提交于 2019-12-04 07:47:36
问题 The complexity of methods in most programming languages can be measured in cyclomatic complexity with static source code analyzers. Is there a similar metric for measuring the complexity of a SQL query? It is simple enough to measure the time it takes a query to return, but what if I just want to be able to quantify how complicated a query is? [Edit/Note] While getting the execution plan is useful, that is not necessarily what I am trying to identify in this case. I am not looking for how