<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Metrics of Moment</title>
    <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Metrics of Moment</title>
      <description>&lt;p&gt;There are two metrics that I think are quite useful in the pursuit of clean code.  One is &lt;a href="http://www.crap4j.org/faq.html"&gt;Crap&lt;/a&gt;, and the other is &lt;a href="http://peripateticaxiom.blogspot.com/2006/05/complexity-and-test-first-0.html"&gt;The Braithwaite Correlation&lt;/a&gt;.  The first is a pragmatic call to action, the second is a measure of overall care.&lt;/p&gt;


	&lt;h2&gt;&lt;span class="caps"&gt;CRAP&lt;/span&gt;&lt;/h2&gt;


	&lt;p&gt;I&amp;#8217;ve written about Crap &lt;a href="http://blog.objectmentor.com/articles/2009/05/20/clean-code-and-battle-scarred-architecture"&gt;before&lt;/a&gt;.  It&amp;#8217;s a very clever metric that combines test coverage and cyclomatic complexity.  You want to keep this metric low.  (FitNesse is currently at &lt;a href="http://internal.objectmentor.com:9090/job/fitnesse/"&gt;0.07&lt;/a&gt;).  Crap will skyrocket if you have a method with high CC and no coverage.  You can bring it down if you 1) split the method up into a group of low CC methods or 2) cover the method with tests or 3) both.&lt;/p&gt;


	&lt;p&gt;One of the more useful elements of &lt;span class="caps"&gt;CRAP&lt;/span&gt; is that it measures the &amp;#8220;crappiness&amp;#8221; of individual methods, and provides you with a list of the worst.  (Fitnesse has &lt;a href="http://internal.objectmentor.com:9090/job/fitnesse/crap/"&gt;very few&lt;/a&gt; crappy methods at the moment.)  This list of crappy methods gives you targets to attack.  You see a method whose &lt;span class="caps"&gt;CRAP&lt;/span&gt; metric is 30, or 50, you target it for decomposition and coverage.  In this way you can engage in a program to bring the &amp;#8220;Crappyness Trend&amp;#8221; (i.e. the ratio of crappy methods to total methods.) down.&lt;/p&gt;


	&lt;p&gt;What is the benefit of brining crappiness down?  Apparently there is a &lt;a href="http://www.enerjy.com/blog/?p=198"&gt;strong correlation&lt;/a&gt; between CC and defects.  So an effort to either reduce CC or increase coverage in high CC modules seems an appropriate way of reducing defects.  Of course the &lt;em&gt;real&lt;/em&gt; reason to target crappy modules is that &lt;span class="caps"&gt;CRAP&lt;/span&gt; is a measure of care&amp;#8212;or rather it&amp;#8217;s lack.&lt;/p&gt;


	&lt;p&gt;If you have high &lt;span class="caps"&gt;CRAP&lt;/span&gt; numbers it simply means that you have been careless with your code.  Big &lt;span class="caps"&gt;CRAP&lt;/span&gt; means that your methods are long, complicated, and untested.  And that&amp;#8217;s just slovenly behavior.  Sorry, that&amp;#8217;s just the way it is.&lt;/p&gt;


	&lt;h2&gt;The Braithwaite Correlation&lt;/h2&gt;


	&lt;p&gt;Despite the fact that this metric sounds like a movie title, this metric  &lt;em&gt;excites&lt;/em&gt; me.  The creator, Keith Braithwaite is duly humble about it; but I think it&amp;#8217;s a significant discovery.  The math behind the metric may be a bit hi-falutin for some folks, but the logic is &lt;em&gt;very&lt;/em&gt; compelling.  If you don&amp;#8217;t know what the terms &amp;#8220;scale-free&amp;#8221;, &amp;#8220;power-law&amp;#8221;, and/or &amp;#8220;log-log&amp;#8221; mean, don&amp;#8217;t worry.  It wouldn&amp;#8217;t hurt you to learn these concepts, but the bottom line is very simple.&lt;/p&gt;


	&lt;p&gt;The Braithwaite Correlation is simply a measure of how many methods have high Cyclomatic-complexity.  Well, OK, that&amp;#8217;s not precisely true.  It&amp;#8217;s actually a measure of how CC is distributed amongst all the methods.  Suffice it to say that if this number is &lt;em&gt;small&lt;/em&gt;, then many methods have a &lt;em&gt;high&lt;/em&gt; CC.  (notice the inversion.)&lt;/p&gt;


	&lt;p&gt;Now here&amp;#8217;s the interesting bit.  BC is not dependent upon the size of the program being measured.  Two different programs that have the same BC, have the same distribution of CC amongst their methods.  One program may have a thousand methods, and the other may have only 20, but the &lt;em&gt;distribution&lt;/em&gt; is the same.  Therefore BC can be viewed in an absolute sense.  For example, we can say that we want our programs to have a BC &amp;gt; 2.&lt;/p&gt;


	&lt;p&gt;Actually the number 2 seems to have a special significance.  Keith&amp;#8217;s research so far shows that programs developed with &lt;span class="caps"&gt;TDD&lt;/span&gt; almost always have a BC greater than 2.  Whereas programs developed without &lt;span class="caps"&gt;TDD&lt;/span&gt; almost always have a BC less than 2.  (FitNesse currently has a BC ~= 2.88)&lt;/p&gt;


	&lt;p&gt;What is the value of measuring BC in your code?  If BC is high it means that your methods are generally small and simple, and that very few are large and complex.  If BC is low, it means that more of your methods are larger and more complicated.  And since we know that CC is strongly correlated with defects, we can surmise that high BC correlates with low defects.&lt;/p&gt;


	&lt;p&gt;But again, the &lt;em&gt;real&lt;/em&gt; reason to keep BC high is that it simply reflects a greater amount of care.&lt;/p&gt;


	&lt;h2&gt;Conclusion&lt;/h2&gt;


	&lt;p&gt;The conclusion is simple.  These metrics are easy to measure&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; and so you should be measuring them &lt;em&gt;now&lt;/em&gt;.  What&amp;#8217;s more, these metrics (especially &lt;span class="caps"&gt;CRAP&lt;/span&gt;) tell you where to focus your energies.  You can take &lt;em&gt;action&lt;/em&gt; that will have an immediate and direct effect on the quality of your code that correlates to defect rate.&lt;/p&gt;


	&lt;p&gt;So what are you waiting for?&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; For java programmers the tools already exist to measure these metrics, and they are very simple to use.   For everyone else, the tools that calculate CC and coverage are readily available.  Combining them to calculate these two metrics just isn&amp;#8217;t that hard.&lt;/p&gt;</description>
      <pubDate>Mon, 08 Jun 2009 11:26:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8c11168a-cf2d-454c-bb15-e41f0de8d1be</guid>
      <author>Uncle Bob</author>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment</link>
    </item>
    <item>
      <title>"Metrics of Moment" by psn card</title>
      <description>&lt;p&gt;Thanks for sharing this great article! That is very interesting Smile I love reading and I am always searching for informative information like this.&lt;/p&gt;</description>
      <pubDate>Tue, 16 Mar 2010 21:54:26 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:615bf2a3-ec0e-4b1c-934e-1532d0b57d36</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-8039</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Lior Friedman</title>
      <description>&lt;p&gt;I hope you might find this effort interesting:&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://imistaken.blogspot.com/2009/10/crap4net.html" rel="nofollow"&gt;http://imistaken.blogspot.com/2009/10/crap4net.html&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;In short I&amp;#8217;ve trying to create a utility for measuring CRAP in the .Net world.&lt;/p&gt;</description>
      <pubDate>Sun, 18 Oct 2009 16:45:54 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:47205be6-a84f-48fa-9eea-211463828115</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-4809</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Clint Shank</title>
      <description>&lt;p&gt;
I recently &lt;a href="http://clintshank.javadevelopersjournal.com/risk_homing_metrics.htm" rel="nofollow"&gt;blogged&lt;/a&gt; about taking CRAP and adding in afferent coupling to really home in on where to focus your energies.
&lt;/p&gt;</description>
      <pubDate>Mon, 22 Jun 2009 11:04:30 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f033224a-ad1f-4ae1-a442-d4678134e05f</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3615</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Ben</title>
      <description>&lt;p&gt;Related to my question about a C++ tool, a beta of CppDepend is now available:
&lt;a href="http://www.cppdepend.com/" rel="nofollow"&gt;http://www.cppdepend.com/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 16 Jun 2009 17:00:22 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:68e4f2a6-edd7-4065-8936-80106ba3a281</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3576</link>
    </item>
    <item>
      <title>"Metrics of Moment" by zvolkov</title>
      <description>&lt;p&gt;As Patrick Smacchia (lead developer on NDepend) pointed out in Hanselminute&amp;#8217;s podcast on NDepend (&lt;a href="http://www.hanselman.com/blog/HanselminutesPodcast51StaticCodeAnalysisWithNDepend.aspx" rel="nofollow"&gt;http://www.hanselman.com/blog/HanselminutesPodcast51StaticCodeAnalysisWithNDepend.aspx&lt;/a&gt;), the aggregate metrics tend to be less intuitive than organic metrics and their absolute values are usually meaningless so they&amp;#8217;re only useful for comparison.&lt;/p&gt;


	&lt;p&gt;Certainly the Crap effect can be achieved by searching for methods with (CC &amp;gt; X &lt;em&gt;and&lt;/em&gt; CoverageRatio &amp;lt; Y)&amp;#8212;much simpler and more useful for the practical purpose of finding methods to refactor.&lt;/p&gt;


	&lt;p&gt;Now, if what you&amp;#8217;re looking for is a single number to show-off on the blog or put on a marketing brochure, the Crap metric may be more useful.&lt;/p&gt;


	&lt;p&gt;This Braithwaite Correlation thing sounds a bit different, but still smells like megapixels if you know what I mean; let&amp;#8217;s wait and see if it flies.&lt;/p&gt;</description>
      <pubDate>Tue, 09 Jun 2009 20:37:08 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:444a008a-e25c-4c41-a87a-804ca0296b4d</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3524</link>
    </item>
    <item>
      <title>"Metrics of Moment" by zvolkov</title>
      <description>&lt;p&gt;As Patrick Smacchia (lead developer on NDepend) pointed out in Hanselminute&amp;#8217;s podcast on NDepend (&lt;a href="http://www.hanselman.com/blog/HanselminutesPodcast51StaticCodeAnalysisWithNDepend.aspx" rel="nofollow"&gt;http://www.hanselman.com/blog/HanselminutesPodcast51StaticCodeAnalysisWithNDepend.aspx&lt;/a&gt;), the aggregate metrics tend to be less intuitive than organic metrics and their absolute values are usually meaningless so they&amp;#8217;re only useful for comparison.&lt;/p&gt;


	&lt;p&gt;Certainly the Crap effect can be achieved by searching for methods with (CC &amp;gt; X &lt;em&gt;and&lt;/em&gt; CoverageRatio &amp;lt; Y)&amp;#8212;much simpler and more useful for the practical purpose of finding methods to refactor.&lt;/p&gt;


	&lt;p&gt;Now, if what you&amp;#8217;re looking for is a single number to show-off on the blog or put on a marketing brochure, the Crap metric may be more useful.&lt;/p&gt;


	&lt;p&gt;This Braithwaite Correlation thing sounds a bit different, but still smells like megapixels if you know what I mean; let&amp;#8217;s wait and see if it flies.&lt;/p&gt;</description>
      <pubDate>Tue, 09 Jun 2009 20:36:13 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:fb9dcba0-22f0-4e77-bd3b-bbcf86a19326</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3523</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Markus G&#228;rtner</title>
      <description>&lt;p&gt;The Braithwaite Correlation can be measured with the download provided on Keith&amp;#8217;s blog: &lt;a href="http://www.keithbraithwaite.demon.co.uk/professional/software/index.html" rel="nofollow"&gt;http://www.keithbraithwaite.demon.co.uk/professional/software/index.html&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m glad that I coult contribute to lowering the CRAP value for FitNesse a bit. What I missed was the full name: Change-Risk Anti-Patterns. CRAP identifies problematic methods in your code base. Currently I feel confident at work in a combination of FindBugs, PMD, CPD, JDepend, Cobertura and Crap4J &amp;#8211; though those builds are nothing to be dealt with all the time, since compilation takes a lot longer. The static code reviewing tools taught me a big deal about the usage of the language as well. On the other hand I&amp;#8217;m aware of using too much and think on cutting these down a bit more.&lt;/p&gt;</description>
      <pubDate>Mon, 08 Jun 2009 14:35:15 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:54f12db5-38f1-478a-b80a-b9b29f498486</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3510</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Ben</title>
      <description>&lt;p&gt;Can you suggest a tool for C++?&lt;/p&gt;</description>
      <pubDate>Mon, 08 Jun 2009 14:24:38 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:665e3913-77b6-4d5e-ae28-2cc6d19902bd</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3509</link>
    </item>
    <item>
      <title>"Metrics of Moment" by Keith Braithwaite</title>
      <description>&lt;p&gt;Blimey.&lt;/p&gt;


	&lt;p&gt;Thanks for your enthusiasm, Bob. Let me inject a little humility right here and point out that the metric which I have been investigating in my spare time the last few years remains very much a work in progress.&lt;/p&gt;


	&lt;p&gt;There are all sorts of open questions about it, and I&amp;#8217;d strongly advise that no-one worries terribly much about the exact value of the metric on their code. That said, I do think it can be a useful guide (only) to the global state of your codebase.&lt;/p&gt;


	&lt;p&gt;Keith&lt;/p&gt;</description>
      <pubDate>Mon, 08 Jun 2009 13:00:16 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0cb6833b-b3c7-4ddd-98a9-5b64c0d7de66</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3508</link>
    </item>
    <item>
      <title>"Metrics of Moment" by tieTYT</title>
      <description>&lt;p&gt;I guess my google skills are weak. I can&amp;#8217;t find the java tools for the Braithwaite Correlation.  Do you have any links?&lt;/p&gt;</description>
      <pubDate>Mon, 08 Jun 2009 12:59:45 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:833aac7e-de73-400f-b9e8-233f3da92165</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/08/metrics-of-moment#comment-3507</link>
    </item>
  </channel>
</rss>
