Click here to Skip to main content
13,795,282 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.1K views
3 bookmarked
Posted 30 Sep 2014
Licenced CPOL

Code Analyzing and NDepend

, 30 Sep 2014
Rate this:
Please Sign up or sign in to vote.
Code analyzing and NDepend

In my childhood, my uncle had shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that, the cloud becomes closer to me and It teaches me one thing that, a deeper-look into something will give you some clues to draw your imagination. You will be able to see that one which you have build-up in your mind.

Years past, after completing my graduation, I start my career as a software engineer but I have noticed that I have not that much passion in my coding and development which I should be to enjoy my profession and I have started asking myself - am I doing any engineering here? Is my code becoming that thing which I have designed in my mind? So to find that answer, I tried that old solution here. I have decided to come closer to my code and start analyzing them. And you know what, it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. Yes, code analyzing is an amazing thing. It helps you see your code quality, matrix, design, dependency, naming conversion, purity, visibility, architecture, layering and even the dead codes in your application.

I have started my first code analyzing tool for DOTNET with FXCOP which I have been introduced to while I was reading a very nice book– Framework Design Guideline. After that, I am hoping to be more closer and have the freedom to go over my code analyzing. I got NDEPEND from Patrick Smacchia who has given me the opportunity to play with NDepend 4. Here, I am picking the NDEPEND to introduce a tool for analyzing your code.

I found some amazing things here in Ndepend:

Why analyze code structure, design, dependencies? It helps you:

  • To avoid dependencies cycles between your components
  • To know about layering and dependencies issues in your code base
  • To prevent design erosion of your code base
  • Care about fabricated complexity and how to reduce it effectively
  • Details the Level metric definition and usage
  • Through Hints on how to componentize existing code
  • To know Dependencies and Concerns
  • To detect All Paths from A to B
  • To re-factore, re-structure and the cost of Levelizing
  • Evolutionary design and Acyclic componentization
  • Understand code: Static vs Dynamic Dependencies

Here is the dependency result for one of my applications:

all

Why build comparison? It will allow you:

  • To write rules that detect API breaking changes
  • To focus code review on code that has been changed and added since the last release
  • To Quality review on code that has been changed and added since a certain milestone
  • To detect when new or refactored code is poorly covered by tests

Ok, now let me talk about the Code Metrics. In Ndepend, I have found Code Metrics on:

  • Application
  • Assemblies (by measuring coupling between types of your application.)
  • Namespaces
  • Type
  • Method
  • Field

Metrics on Application is going to give you the following:

  • Lines of Code (NDepend computes this metric directly from the info provided in PDB files. The LOC for a method is equal to the number of sequence point found for this method in the PDB file. A sequence point is used to mark a spot in the IL code that corresponds to a specific location in the original source.)
  • Lines of Comments (Ndepend needs PDB files present and its corresponding source files)
  • Comment Percentage
  • Lines of code covered
  • Lines of code not covered
  • And all five things mention above (Assemblies ,Namespaces, Type, Methods and Fields)

Metrics on assemblies, Namespaces, Type, methods and Fields(only Afferent Coupling) allow you to find two main coupling here on their respective level:

  • Afferent Coupling
  • Efferent coupling

Other things of Metrics on assemblies

  • Relational Cohesion
  • Instability
  • Abstractness
  • Distance from main sequence

Other things of Metrics on Namespaces

  • Level (defined for assemblies, namespaces, types, methods)

Other things of Metrics on Type

  • Lack of Cohesion Of Methods
  • Cyclomatic Complexity (defined for types, methods)
  • IL Cyclomatic Complexity
  • Size of instance (defined for instance fields and types)
  • Interfaces Implemented
  • Number of Children
  • Depth of Inheritance Tree

Other things of Metrics on Methods

  • IL Nesting Depth
  • Parameters
  • Variables
  • Overloads
  • Percentage Branch Coverage

Here is the Matrices result on one of my current applications:

What more:

Yes, it has lot more things like code quality, matrix, design, dependency, naming conversion, purity, visibility, architecture, layering and even the dead codes in your application.

Take a look into this result shot:

And also thing like:

  • Warnings on Build Process Health
  • Harness Test Coverage Data
  • API and Power tools.

But the most exciting features that I like here is Code Rule and Code Query over LINQ. It's amazing!!!!! Also, it has the intelligence support.

Here are some examples that I have tried in my application.

Here, in the first example, I have tried to look into the type, found number of methods and field declared there.

And another example to search all fields which start with a certain string – say Jericho and also export the result into HTML.

It seems pretty cool to me that allows me to deep drive into my application.

Hope it will help you to introduce with Ndepend and Code analyzing. Thanks guys for reading Smile.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Morshed Anwar
Team Leader PracticePRO Software Systems Inc
United States United States
"In my childhood, my uncle has shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that the cloud becomes closer to me and It teaches me one thing that, a deeper-look to something will give you some clues to draw your imagination. You can able to see that one which you have build-up in your mind.

Years past, I have started my career as a software engineer and has been looking for passion in my coding and development which I should be to enjoy my profession and has started asking myself- 'am I doing any engineering here?!' Is my code becoming that thing which I have designed in my mind? So to find that answer I have tried that old solution here... I have decided to come closer to my code and start analyzing them. And it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. It also helps me to think out of the box, solve each problems by making blocks and make me careful on each steps." ----- says Morshed Anwar.

• Morshed's Technical Blog site: http://morshedanwar.wordpress.com/

• Morshed's Technical articles those are published in Codeproject site: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=2992452

• Morshed's Linkedin profile: http://www.linkedin.com/in/morshedanwar

• Morshed's Facebook Profile : http://www.facebook.com/morshed.pulok

Beside all these Morshed like to do - photography and music. Here is Morshed's Flickr photos : http://www.flickr.com/photos/morshed_anwar/

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 103381051-Oct-14 9:45
memberMember 103381051-Oct-14 9:45 
QuestionThanks, but you should mention... Pin
rht3411-Oct-14 4:33
memberrht3411-Oct-14 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181207.3 | Last Updated 30 Sep 2014
Article Copyright 2014 by Morshed Anwar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid