Geeks With Blogs
Caffeinated Coder A Grande, Triple Shot, Non-Fat Core Dump by Russell Ball

In my recent post on code quality, I mentioned some of the high level features of a static analysis tool called NDepend. I've been exploring some of the pre-built CQL (Code Query Language) queries in the tool by running them against the WatiN codebase. Here are the results from selecting "Types with Too Many Methods" query. NDepend shows you a list of the classes and number of methods in each on the left along with a visual Tree Map visual representation on the bottom. 

Once code is analyzed while first loading the assembly, the GUI is blazingly fast and dynamically updates whenever you highlight a new query. You can modify queries to suite your own standards and then double click to drill into the exact spot in the code. Here is what the CQL query looks like for identifying types with excessive methods:


Here are some other pre-built queries that I found especially compelling:

  1. Methods too big ( > 30 lines of code)
  2. Methods with too many parameters ( > 5)
  3. Too many local variables ( > 15)
  4. Methods too complex (cyclomatic complexity > 20)
  5. Poorly commented (% comment < 20 and # lines > 10)
  6. Fragile base class (depth of inheritance > 6)

NDepend showed that WatiN had the following issues that could potentially be refactoring opportunities.

  1. One method with too many parameters (SendMessageTimeout has 7)
  2. Ten classes with too many methods (Document has 97)

There are also a very helpful group of queries that are designed to just help you better understand the codebase by identifying the most used methods, types, and namespaces.

As an interesting aside, this tool seems to have been written entirely by one person, Patrick Smaccia. I want to personally thank him for giving me indisputable proof that I barely qualify for a bottom-dwelling, plankton-like status on the alpha-geek food chain.

Posted on Tuesday, September 18, 2007 8:06 AM Software Development Practices , Tools | Back to top

Comments on this post: Analyzing WatiN Code Quality with NDepend's CQL

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Russell Ball | Powered by: