Code Analyzing and NDepend
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 more close 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, after completing my graduation, I start my career as a software engineer but I have notice 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 have tried that old solution here. I have decided to come closer to my code 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 while I was reading a very nice book– Framework Design Guideline. After that I am hoping to more closer and 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 NDEPND to introduce a tool for analyzing you code.
I found some amazing things here in Ndepend :
- Conventions / Rules / Constraints
- Code Structure, Design, Dependencies
- Build comparison
- Code Coverage
- Build Process / CI integration
- Usability and Ergonomy ramblings
- .NET Performances
Why Analyzing 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-factoring, Re-Structuring and the cost of Levelizing
- Evolutionary Design and Acyclic componentization
- Understanding Code: Static vs Dynamic Dependencies
Here is the dependency result for one of my Application:
Why Build Comparison? It will allow you -
- To write rules that detects API breaking changes.
- To focus code review on code that have been changed and added since the last release.
- To Quality review on code that have 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:
- Assemblies (by measuring coupling between types of your application.)
Metrics on Application gonna 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 equals 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 find two main coupling here on their respective level –
- Afferent Coupling
- Efferent coupling
Other things of Metrics on assemblies –
- Relational Cohesion
- 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
- Percentage Branch Coverage
Here is the Matrices result on one of current application:
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. Its Amazing!!!!! Also it has the intelligence support.
Here are some examples that I have tried to my application
Here in first example I have tried to look into the type, found no 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 allow me to deep drive into my application.
Hope it will help you to introduce with Ndepend and Code analyzing. Thanks guys for reading .