<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Chewing the fat over cyclomatic complexity</title>
	<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/</link>
	<description>Can you dig it man?</description>
	<pubDate>Wed, 09 Jul 2008 05:02:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Software Company</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-63882</link>
		<dc:creator>Software Company</dc:creator>
		<pubDate>Wed, 04 Jun 2008 16:48:21 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-63882</guid>
		<description>hey

Really nice tips!

will try to keep it in my mind 

thanks!</description>
		<content:encoded><![CDATA[<p>hey</p>
<p>Really nice tips!</p>
<p>will try to keep it in my mind </p>
<p>thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas McCabe Jr.</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-45208</link>
		<dc:creator>Thomas McCabe Jr.</dc:creator>
		<pubDate>Fri, 22 Feb 2008 14:39:13 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-45208</guid>
		<description>Hello All,

I have been aware of the CRAP metric for a while now but have only taken a cursory look, and therefore have not formulated an opinion on the subject.  However, I have seen organizations obtain value from the McCabe cyclomatic complexity metric, not only on its own but also in conjunction with other metrics.  For example, metrics such as one which gives the ratio of cyclomatic complexity to SLOC, the essential density (ratio of unstructured paths to cyclomatic), the design complexity (cyclomatic paths related to calls to other modules), and others. 

Cyclomatic complexity measures control flow. The reason why case and switch statements add to cyclomatic complexity is because you do indeed need to test the control flow associated with the case and switch statements. 

However, the one acknowledged exception to limiting the cyclomatic complexity to ten (10) are modules that include a switch or case statement (some can be very large). If you have perfectly structured switch and case statements (and also avoid jumping into loops/decisions and out of loops/decisions within the rest of the logic) the McCabe essential complexity will always be one (1) indicating a perfectly well structured module. McCabe essential complexity is bounded by the cyclomatic complexity and guides in modularizing or partitioning high cyclomatic modules into smaller more understandable pieces.
 
Frequently, software engineers obtain cyclomatic complexity values to understand the complexity level, but do not then use it as part of the total Structured Testing Methodology as described in the NIST document (http://www.mccabe.com/iq_research_nist.htm).  Being cognizant of cyclomatic paths enables one to catch errors that deal with the interactions of code constructs, which results in higher reliability.  Some of the bloggers are hitting on this thought - that the cyclomatic complexity (even as it is incremented for all outcomes of a switch outcome) can at least help you be aware of all paths, so you can make more informed decisions about your testing effort.  More info on this subject can be at 

http://www.mccabe.com/iq_research_appNotes_1.htm.</description>
		<content:encoded><![CDATA[<p>Hello All,</p>
<p>I have been aware of the CRAP metric for a while now but have only taken a cursory look, and therefore have not formulated an opinion on the subject.  However, I have seen organizations obtain value from the McCabe cyclomatic complexity metric, not only on its own but also in conjunction with other metrics.  For example, metrics such as one which gives the ratio of cyclomatic complexity to SLOC, the essential density (ratio of unstructured paths to cyclomatic), the design complexity (cyclomatic paths related to calls to other modules), and others. </p>
<p>Cyclomatic complexity measures control flow. The reason why case and switch statements add to cyclomatic complexity is because you do indeed need to test the control flow associated with the case and switch statements. </p>
<p>However, the one acknowledged exception to limiting the cyclomatic complexity to ten (10) are modules that include a switch or case statement (some can be very large). If you have perfectly structured switch and case statements (and also avoid jumping into loops/decisions and out of loops/decisions within the rest of the logic) the McCabe essential complexity will always be one (1) indicating a perfectly well structured module. McCabe essential complexity is bounded by the cyclomatic complexity and guides in modularizing or partitioning high cyclomatic modules into smaller more understandable pieces.</p>
<p>Frequently, software engineers obtain cyclomatic complexity values to understand the complexity level, but do not then use it as part of the total Structured Testing Methodology as described in the NIST document (http://www.mccabe.com/iq_research_nist.htm).  Being cognizant of cyclomatic paths enables one to catch errors that deal with the interactions of code constructs, which results in higher reliability.  Some of the bloggers are hitting on this thought - that the cyclomatic complexity (even as it is incremented for all outcomes of a switch outcome) can at least help you be aware of all paths, so you can make more informed decisions about your testing effort.  More info on this subject can be at </p>
<p><a href="http://www.mccabe.com/iq_research_appNotes_1.htm." rel="nofollow">http://www.mccabe.com/iq_research_appNotes_1.htm.</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44546</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Mon, 18 Feb 2008 12:05:03 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44546</guid>
		<description>( The on() rule engine code is better though, it can check for errors and it's easier to debug, it could draw a diagramm or print itself nicely to make debugging easier. And there is no problem with break and people can only call correct commands, not all legal Java code. So perhaps CCN is an indicator that there is a problem with the switch code )

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>( The on() rule engine code is better though, it can check for errors and it&#8217;s easier to debug, it could draw a diagramm or print itself nicely to make debugging easier. And there is no problem with break and people can only call correct commands, not all legal Java code. So perhaps CCN is an indicator that there is a problem with the switch code )</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44545</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Mon, 18 Feb 2008 12:00:24 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44545</guid>
		<description>The switch statement is problematic, I would probably use a simple rule engine for that case. 

Your view is valid though I think. Different, but equivalent code, has different CCNs.

case 1: lowerTemperature(3); break;
case 2: lowerTemperature(2); break;

has a higher CCN than (Simple doItYourself Java rule engine):

on(1).adjust(lowerTemperature(3));
on(2).adjust(lowerTemperature(2));

although both fragments do the same and perhaps, have the same complexity.

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>The switch statement is problematic, I would probably use a simple rule engine for that case. </p>
<p>Your view is valid though I think. Different, but equivalent code, has different CCNs.</p>
<p>case 1: lowerTemperature(3); break;<br />
case 2: lowerTemperature(2); break;</p>
<p>has a higher CCN than (Simple doItYourself Java rule engine):</p>
<p>on(1).adjust(lowerTemperature(3));<br />
on(2).adjust(lowerTemperature(2));</p>
<p>although both fragments do the same and perhaps, have the same complexity.</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Binstock</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44125</link>
		<dc:creator>Andrew Binstock</dc:creator>
		<pubDate>Sat, 16 Feb 2008 05:28:28 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44125</guid>
		<description>@Rich: The analysis in your original post on CCN is more accurate than the statement you make here. In fact, if we look at the chart you generated, (http://www.enerjy.com/blog/wp-content/uploads/2008/02/mccabegraph.jpg), low CCN counts have a *higher* bug expectancy up to a CCN of 11. 

Moreover, up to a CCN of 25 or so, there is no correlation between CCN and bug frequency. A higher CCN value has equal probability of matching higher or lower bug counts in that range.

And since my experience is that the *vast* majority of Java methods have CCN of &#60; 25, I think it's more accurate to say that for the majority of Java code, CCN in fact is not a useful predictor of quality--nor of how many unit tests you should be writing. Above 25, as you state in the original post, CCN does correlate to an increasing bugginess.</description>
		<content:encoded><![CDATA[<p>@Rich: The analysis in your original post on CCN is more accurate than the statement you make here. In fact, if we look at the chart you generated, (http://www.enerjy.com/blog/wp-content/uploads/2008/02/mccabegraph.jpg), low CCN counts have a *higher* bug expectancy up to a CCN of 11. </p>
<p>Moreover, up to a CCN of 25 or so, there is no correlation between CCN and bug frequency. A higher CCN value has equal probability of matching higher or lower bug counts in that range.</p>
<p>And since my experience is that the *vast* majority of Java methods have CCN of &lt; 25, I think it&#8217;s more accurate to say that for the majority of Java code, CCN in fact is not a useful predictor of quality&#8211;nor of how many unit tests you should be writing. Above 25, as you state in the original post, CCN does correlate to an increasing bugginess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Binstock</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44039</link>
		<dc:creator>Andrew Binstock</dc:creator>
		<pubDate>Fri, 15 Feb 2008 19:33:30 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44039</guid>
		<description>Your analysis in your original post on CCN is more accurate than the statement you make here. In fact, if we look at the chart you generated, (http://www.enerjy.com/blog/wp-content/uploads/2008/02/mccabegraph.jpg) very low CCN counts have a *higher* bug expectancy up to a CCN of 11. CCNs of 1-11 cover a large fraction of Java routines. Moreover, up to a CCN of 25 or so, there is no correlation between CCN and bug frequency. A higher CCN value has equal probability of raising or lowering bug counts in that range.

And since my experience is that the vast majority of Java methods have CCN of &#60; 25, I think it's more accurate to say that for the majority of Java code, CCN in fact is not a useful indicator of quality--nor of how many unit tests you should be writing.</description>
		<content:encoded><![CDATA[<p>Your analysis in your original post on CCN is more accurate than the statement you make here. In fact, if we look at the chart you generated, (http://www.enerjy.com/blog/wp-content/uploads/2008/02/mccabegraph.jpg) very low CCN counts have a *higher* bug expectancy up to a CCN of 11. CCNs of 1-11 cover a large fraction of Java routines. Moreover, up to a CCN of 25 or so, there is no correlation between CCN and bug frequency. A higher CCN value has equal probability of raising or lowering bug counts in that range.</p>
<p>And since my experience is that the vast majority of Java methods have CCN of &lt; 25, I think it&#8217;s more accurate to say that for the majority of Java code, CCN in fact is not a useful indicator of quality&#8211;nor of how many unit tests you should be writing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44027</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Fri, 15 Feb 2008 18:18:18 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44027</guid>
		<description>Chris wrote:

"..that amount of complexity *may not be enough to say the code is buggy..."

Our &lt;a href="http://www.enerjy.com/blog/?p=241" rel="nofollow"&gt;follow up blog&lt;/a&gt; to the video we posted on different peoples views, proves that it is indeed &lt;i&gt;probable&lt;/i&gt; that, knowing &lt;b&gt;nothing&lt;/b&gt; else about a file, having a higher McCabe value is enough to be fault-prone.

Of course nothing in this industry is certain...</description>
		<content:encoded><![CDATA[<p>Chris wrote:</p>
<p>&#8220;..that amount of complexity *may not be enough to say the code is buggy&#8230;&#8221;</p>
<p>Our <a href="http://www.enerjy.com/blog/?p=241" rel="nofollow">follow up blog</a> to the video we posted on different peoples views, proves that it is indeed <i>probable</i> that, knowing <b>nothing</b> else about a file, having a higher McCabe value is enough to be fault-prone.</p>
<p>Of course nothing in this industry is certain&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Disco Blog &#187; Blog Archive &#187; The weekly bag&#8211; Feb 15</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44015</link>
		<dc:creator>The Disco Blog &#187; Blog Archive &#187; The weekly bag&#8211; Feb 15</dc:creator>
		<pubDate>Fri, 15 Feb 2008 16:32:20 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-44015</guid>
		<description>[...] Chewing the fat over switch statements and CCN- Andrew Binstock and Chris have a copasetic discussion going on through comments regarding CCN and switch statements. This is a great read! [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Chewing the fat over switch statements and CCN- Andrew Binstock and Chris have a copasetic discussion going on through comments regarding CCN and switch statements. This is a great read! [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Binstock</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-43944</link>
		<dc:creator>Andrew Binstock</dc:creator>
		<pubDate>Fri, 15 Feb 2008 08:20:38 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-43944</guid>
		<description>If different values in the switch statement call different methods, as in my example, a table is a non-starter. You could use a map and the command pattern. However, the command pattern does not reduce complexity, it simply redistributes the complexity throughout your project--and all the new objects need tests of their own. Whereas a single class with a single switch statement is completely clear and much easier to verify. (Agreed that if the case statements become more than simple do-this, do-that commands, then you have to abandon the switch.)

Anyhow, it would be more fun to have this dialogue over a beer. (I'll be at CITcon and JavaOne.) My original point is that CCR's measure of complexity is flawed in how it counts switch statements. Simple case statements are surely less complex that the equivalent number of if/else statements, so I think they should have a lower level of complexity.</description>
		<content:encoded><![CDATA[<p>If different values in the switch statement call different methods, as in my example, a table is a non-starter. You could use a map and the command pattern. However, the command pattern does not reduce complexity, it simply redistributes the complexity throughout your project&#8211;and all the new objects need tests of their own. Whereas a single class with a single switch statement is completely clear and much easier to verify. (Agreed that if the case statements become more than simple do-this, do-that commands, then you have to abandon the switch.)</p>
<p>Anyhow, it would be more fun to have this dialogue over a beer. (I&#8217;ll be at CITcon and JavaOne.) My original point is that CCR&#8217;s measure of complexity is flawed in how it counts switch statements. Simple case statements are surely less complex that the equivalent number of if/else statements, so I think they should have a lower level of complexity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-43781</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 14 Feb 2008 16:06:23 +0000</pubDate>
		<guid>http://thediscoblog.com/2008/02/13/chewing-the-fat-over-cyclomatic-complexity/#comment-43781</guid>
		<description>In this case a table of temperatures to reduce keyed off the temperature would be a better, more maintainable solution.

Handed a method with over 30 branch points *is* a problem. Even if you test every line 100% (which CRAP takes into account) the sheer amount of branch points means:

1) A huge number of test cases to hit 100% line &#38; branch coverage
2) A high amount of refactoring if the the assumption this code is based on changes

The metric here would say, high complexity with 100% test coverage... ok so far so good. Then it says... you know what... that amount of complexity *may not be enough to say the code is buggy but chances are good it can and will become buggy later on when maintenance of the code occurs*.

The above example is almost like an example pulled straight out of "Refactoring to Patterns" [Fowler]. It *can* be made more maintainable.</description>
		<content:encoded><![CDATA[<p>In this case a table of temperatures to reduce keyed off the temperature would be a better, more maintainable solution.</p>
<p>Handed a method with over 30 branch points *is* a problem. Even if you test every line 100% (which CRAP takes into account) the sheer amount of branch points means:</p>
<p>1) A huge number of test cases to hit 100% line &amp; branch coverage<br />
2) A high amount of refactoring if the the assumption this code is based on changes</p>
<p>The metric here would say, high complexity with 100% test coverage&#8230; ok so far so good. Then it says&#8230; you know what&#8230; that amount of complexity *may not be enough to say the code is buggy but chances are good it can and will become buggy later on when maintenance of the code occurs*.</p>
<p>The above example is almost like an example pulled straight out of &#8220;Refactoring to Patterns&#8221; [Fowler]. It *can* be made more maintainable.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
