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:
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:
- Assemblies (by measuring coupling between types of your application.)
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
- 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 my current applications:
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 .