CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo [MVP]

Software management consultant and CTO, Headspring Systems

Code analysis from an XP project - level 300

I've posted on a retrospective of my team's current release, and I've run a few code analysis numbers to get a baseline trend.

I normally don't do code analysis since working code is our real goal, but here it is:
I analyzed our latest component, which is a part of a larger software product.  This component delivers tremendous business value, and it was developed from scratch on my team using XP methods.  Here's the stats:
Statements: 6600
Productions statements: 2500.  The rest is test code.
Number of classes 141 - 71 production classes.  The rest are test classes.
7.5 methods per class.
About 5 lines of code per method on average.
Maximum cyclomatic complexity of any method: 6.  Average is 1.5

We have a few methods that are close to 20 lines of code, but the number of those can be counted on 1 hand.

This release has seen very few bugs
I don't see any value in using code metrics as a direct measurement of the quality of the code.  It may be a trend, but there is no causality between the two.  It is, however, interesting to look at the trends from time to time.

  • We ended up with 2 times as much test code as production code.
  • Our classes ended up very small.  Our methods even smaller.
  • Our method cyclomatic complexity averaged between 1 and 2.
  • We ended up with about 5 actual bugs in the release.  This might seem unreal, but I credit all the automated test coverage for this result.
I know some of you will cringe at the thought of writing two times as much test code as production code, but given the results we have achieved, I consider it worth it.


Comments

Maruis Marais said:

It is really funny you would say that people would cringe when they hear you remarking about the amount of test code your team wrote. But the interesting thing is you can't measure the amount of time that was cut from looking at a yellow line of a debugger. Probably the only artifact is the keyboards lasting longer, since the whole keyboard is used and not only the F10 and F11 buttons.

Another interesting fact I found was that the amount of time spent isolating a bug or issue also dropped drastically, due to the ability to validate the code quicker with existing unit tests. We found that probably 90% of our bugs where found in code that wasn't covered by unit tests.

# April 13, 2006 11:50 PM

Jeffrey Palermo said:

Maruis.   Debugging time was definitely cut out drastically.  Unit test do isolate issues as you state.

We found a couple of bugs in code, and as you say, it was code that didn't have an integration test guarding it.
# April 13, 2006 11:56 PM

Jeremy D. Miller said:

LoL, Maruis
# April 14, 2006 12:05 AM

Jason Haley said:

# April 14, 2006 7:07 AM

Brendan said:

Jeffrey, does this go throug?
# April 14, 2006 4:10 PM

use_TDD_name_or_not said:

Do you use nmock or similar things? if yes, how much? do you use unit test your UI code?
# April 18, 2006 10:01 PM

About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

This Blog

Syndication