Saturday, November 27, 2010

NDepend :- Part II

Quite from some time I was thinking about using NDepend to check my code with the yardstick of standard metrics . I finally got free and started to dig , how I can use NDepend to catch loose points in the code ?  NDepend analysis is the process of capturing all the information from the code that can be used as a metrics for measuring and calculating the quality and stability of the code.

Metrics has always been used in other sciences as a measure of the property of some tangible element. But in software development process, where software as an outcome is considered intangible , applying metrics and deducting the meaning out of them has been subject to open discussion. But with advance in the process of software development , many standard and time tested metrics has been setup. NDepend is based on these standard metrics. Tool provides the way to capture the information and present us with the detailed report of all these metrics.

So to utilize the NDepend to its full potential , we have to look at two core component of NDepend , NDepend metrics and CQL. Starting with metrics,  NDepend provides the list of all the metrics it uses and also the values for metrics that should be considered as standard for good quality code (http://www.ndepend.com/Metrics.aspx ). NDepend's metrics page also provides some links to the patrick smacchia blogs at codebetter.com, that can helps us to understand the usefulness and relevance of the code metrics in relation to code analysis.  Some of the links that you might want to check out are :-

http://codebetter.com/blogs/patricksmacchia/archive/2007/10/05/why-is-it-useful-to-count-the-number-of-lines-of-code-loc.aspx

http://codebetter.com/blogs/patricksmacchia/archive/2008/02/15/code-metrics-on-coupling-dead-code-design-flaws-and-re-engineering.aspx

http://codebetter.com/blogs/patricksmacchia/archive/2008/03/07/a-simple-trick-to-code-better-and-to-increase-testability.aspx

After understanding one of key component of NDepend ,  NDepend’s metrics. We now can move forward to other core component CQL (Code Query Language). CQL is easy to use query language , used in NDepend .It is similar to SQL and we can easily write intuitive queries . CQL works on metrics and code structure of .Net application and fetches the result for the query. NDepend constraints are based on the CQL and checks for any violation.

CQL is one of my favourite feature of NDepend , as it is similar to SQL so it is easy for me or any developer to write queries against the .Net code structure and metrics. We can easily write a query to find out all the methods in particular namespace where the no of lines of code or IL code is greater than 250 and then can factor out these big methods in small ones .

Ex:-

WARN IF Count > 0 IN SELECT METHODS OUT OF NAMESPACES "MyNameSpace.GUI"  WHERE NbILInstructions > 200

CQL editor of NDepend provides intellisense for query writing and we can turn our CQL queries into constraints and check for any violation with successive builds.  To see the power of CQL and various samples,  you can check out this link:- 

http://www.ndepend.com/CQL.htm

NDepend also presents a visual layout of analysis as Dependency Graph and Dependency Matrix , we can use these visual tools to see entire picture of our codebase and its composition with perspective of metrics.

But with knowledge of software metrics and instrument as CQL we can explore and have control over the process of software development to achieve high quality code.

I am still new to NDepend and feeling like I have just discovered the tip of iceberg.

No comments:

Post a Comment