Code Metrics - Complexity & The .NET Framework...

Tags: .NET, .NET Framework, C#, VB.NET

 

If you have never heard of "Cyclomatic Complexity" a good place to start is here. I decided to grab the Reflector Addin by Peli which will examine an assembly's methods and produce a list of code metrics for each given method, one of which is the Cyclomatic Complexity and run it on "mscorlib.dll" and some of the results are actually quite alarming.

Just in this one DLL there are 24 methods that score 50 or higher, the highest being DateTimeParse.ParseByFormat() which scores at 98.  Now if you look at Table 4 in the article I linked above you will notice that they state that "greater than 50 - untetsable program (very hight risk)"

I would love to see the code coverage report on these methods.  How much of these top methods are actually being testing?  How thorough is their process for getting these "untestable" methods tested.  I would also like to see the number of bug reports for each method > 50 in the framework and compare those to those < 50...

 

I decided to dig a bit deeper than just mscorlib.dll.  Here are some of the things I found...

System.dll  has 20 methods > 50 with the worst at 178

    HttpRequestCacheValidator.FetchCacheControl(String, Boolean) : Void 

 

System.Data.dll has  14 methods > 50 with the worst at 118

     BinaryNode.EvalBinaryOp(Int32, ExpressionNode, ExpressionNode, DataRow, DataRowVersion, Int32[]) : Object 

 

System.Drawing.dll has NO methods > 50, with the worst at 29

    Icon.Initialize(Int32, Int32) : Void

System.Web.dll has 19 methods > 50, with the worst at 184

    BrowserCapabilitiesFactory.UpProcess(NameValueCollection, HttpBrowserCapabilities) : Boolean 

 

System.Windows.Forms.dll has 35 methods > 50, with the worst at 169

    DataGridView.GetClipboardContent() : DataObject

 

System.Configuration.dll has 3 methods > 50, with the worst at 89

    ConfigurationElement.DeserializeElement(XmlReader, Boolean) : Void

 

System.Security.dll has NO methods > 50, with the worst at  35

    Reference.CalculateHashValue(XmlDocument, CanonicalXmlNodeList) : Byte[]

 

and the all time worst method for Cyclomatic Complexity is...

 

System.Xml.dll has 15 methods > 50, with the worst at 224

    XmlSchemaInference.InferSimpleType(String, Boolean&) : Int32

 
Also, it has 1557 instructions, 31 locals..

How can anyone test this accurately?

 

3 Comments

Comments have been disabled for this content.