Discussion:
Cyclomatic Complexity (per class and per method)
S. Hendriks
2010-04-15 13:43:35 UTC
Permalink
Hi,



I’ve a question about the Cyclomatic Complexity.



At the dashboard I see this:





I am wondering, what is the total complexity of this project? Do I take the
2,5 per method? Or do I take the 14,7 per class?


And to make it more confusing. The Total Quality Plugin says: Design Classes
and Methods Complexity à 77.9%



What I’m looking for is the complexity score of McCabe. So I figured the
numbers on the dashboard where ok. Should I read it as:

2.6 à Complexity average per method

14.7 à Complexity average per class



?



If so, what would be the most accurate decision if I wanted to tell
something about the entire project. My gut feeling says I should take per
class (the 14.7).



Any advice is appreciated,



Regards,



Stefan
e72636 e72636
2010-04-15 13:55:35 UTC
Permalink
Hi, metrics related to design complexity are the % of classes with a higher
value to a given ceiling (configurable in the administration page). By
default 2.5 for methods and 12 for classes.

http://docs.codehaus.org/display/SONAR/Total+Quality+Plugin
https://svn.codehaus.org/sonar-plugins/trunk/total-quality/src/main/java/org/sonar/plugins/totalquality/DesignNOMDecorator.java

Regards,

Martin.
Post by S. Hendriks
Hi,
I’ve a question about the Cyclomatic Complexity.
I am wondering, what is the total complexity of this project? Do I take the
2,5 per method? Or do I take the 14,7 per class?
And to make it more confusing. The Total Quality Plugin says: Design *Classes
and Methods* Complexity à 77.9%
What I’m looking for is the complexity score of McCabe. So I figured the
2.6 à Complexity average per method
14.7 à Complexity average per class
?
If so, what would be the most accurate decision if I wanted to tell
something about the entire project. My gut feeling says I should take per
class (the 14.7).
Any advice is appreciated,
Regards,
Stefan
Yanko, Curtis
2010-04-15 13:57:55 UTC
Permalink
Interesting. I found the normalization of the data to be helpful since total complexity is a function of Size and not necessarily nindicator that we should take action.

I thought I saw total complexity somewhere... to me that would be helpful in estimating effort or considering total risk.

===========================
Curtis Yanko
UHGIT
Computer Services - ADIS
Continuous Integration Service
https://ulink.uhc.com/groups/cis
w860.702.9059
m860.881.2050


________________________________

From: S. Hendriks [mailto:stefanhen83-***@public.gmane.org]
Sent: Thursday, April 15, 2010 9:44 AM
To: user-***@public.gmane.org
Subject: [sonar-user] Cyclomatic Complexity (per class and per method)



Hi,



I've a question about the Cyclomatic Complexity.



At the dashboard I see this:





I am wondering, what is the total complexity of this project? Do I take the 2,5 per method? Or do I take the 14,7 per class?


And to make it more confusing. The Total Quality Plugin says: Design Classes and Methods Complexity à 77.9%



What I'm looking for is the complexity score of McCabe. So I figured the numbers on the dashboard where ok. Should I read it as:

2.6 à Complexity average per method

14.7 à Complexity average per class



?



If so, what would be the most accurate decision if I wanted to tell something about the entire project. My gut feeling says I should take per class (the 14.7).



Any advice is appreciated,



Regards,



Stefan


This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.
S. Hendriks
2010-04-15 14:10:16 UTC
Permalink
I think it would be interesting trend-wise to see if the project itself is
getting more complex or not.



I’m still puzzled what the complexity of a class means. I can see the
meaning of complexity for one method. For a class would (to me) give the
impression that it somehow has been added (= sum of all CC of all methods).



If I had to make a judgement of the entire project, I would probably take
the average class CC as indicator. Meaning I have a lot of methods sitting
in classes doing complex stuff and that I should cut it up into more pieces.
Not only because of CC, but I bet it has a negative influence on cohesion
and such as well.



As for:

“Hi, metrics related to design complexity are the % of classes with a higher
value to a given ceiling (configurable in the administration page). By
default 2.5 for methods and 12 for classes.”



That’s a nice approach as well.



I’ll dig into this further.



Regards,



Stefan



Van: Yanko, Curtis [mailto:curt_yanko-***@public.gmane.org]
Verzonden: donderdag 15 april 2010 15:58
Aan: user-***@public.gmane.org
Onderwerp: RE: [sonar-user] Cyclomatic Complexity (per class and per method)



Interesting. I found the normalization of the data to be helpful since total
complexity is a function of Size and not necessarily nindicator that we
should take action.



I thought I saw total complexity somewhere... to me that would be helpful in
estimating effort or considering total risk.



===========================

Curtis Yanko

UHGIT

Computer Services - ADIS

Continuous Integration Service

https://ulink.uhc.com/groups/cis

w860.702.9059

m860.881.2050





_____

From: S. Hendriks [mailto:stefanhen83-***@public.gmane.org]
Sent: Thursday, April 15, 2010 9:44 AM
To: user-***@public.gmane.org
Subject: [sonar-user] Cyclomatic Complexity (per class and per method)

Hi,



I’ve a question about the Cyclomatic Complexity.



At the dashboard I see this:





I am wondering, what is the total complexity of this project? Do I take the
2,5 per method? Or do I take the 14,7 per class?


And to make it more confusing. The Total Quality Plugin says: Design Classes
and Methods Complexity à 77.9%



What I’m looking for is the complexity score of McCabe. So I figured the
numbers on the dashboard where ok. Should I read it as:

2.6 à Complexity average per method

14.7 à Complexity average per class



?



If so, what would be the most accurate decision if I wanted to tell
something about the entire project. My gut feeling says I should take per
class (the 14.7).



Any advice is appreciated,



Regards,



Stefan




This e-mail, including attachments, may include confidential and/or


proprietary information, and may be used only by the person or entity


to which it is addressed. If the reader of this e-mail is not the intended


recipient or his or her authorized agent, the reader is hereby notified


that any dissemination, distribution or copying of this e-mail is


prohibited. If you have received this e-mail in error, please notify the


sender by replying to this message and delete this e-mail immediately.
Goettlicher Harald (AA-DGP/ESD2)
2010-04-15 14:03:19 UTC
Permalink
There is no generic answer, you have to set your own goals or warning levels for both class and method values.
See this mail from a former discussion.

Harald

________________________________
Von: Freddy Mallet [mailto:freddy.mallet-***@public.gmane.org]
Gesendet: Mittwoch, 16. September 2009 09:29
An: user-***@public.gmane.org
Betreff: Re: [sonar-user] Method and class complexity

Hi Jose,

I'm more or less comfortable with the results Sonar is showing except for the complexity box. Right now I'm seeing:

Method complexity: 2.0
Class complexity: 14.6

These are some mean values which tell you "globally" if your business complexity has been correctly split into small and manageable piece of code (method and class level). In your case, 2 and 14.6 are pretty good values as we consider 3 and 30 to be warning thresholds.

But in the later case I see individual classes with a complexity of 70. But.. is this much or not?

Even if you have good means, some isolated classes can be considered as code smell. But in your case 70 is still a correct value. We consider 100 to be the warning threshold at class level.

For methods you have the cyclomatic complexity that more or less helps to know when to split the logic but there's nothing similar for classes. Aganist what can I compare values? Could the complexity be calculated as a percentage as well? Percentages give a good measure of quality quickly.

In fact I'm currently working on Sonar Squid to calculate OO metrics and one of them will be very valuable to know if a class must be slept or not : this is the LCOM4 (http://www.aivosto.com/project/help/pm-oo-cohesion.html<BLOCKED::http://www.aivosto.com/project/help/pm-oo-cohesion.html>).

regards,
Freddy
Continue reading on narkive:
Search results for 'Cyclomatic Complexity (per class and per method)' (Questions and Answers)
5
replies
Do we really need software metrics?
started 2007-04-04 06:30:54 UTC
programming & design
Loading...