Thursday, May 15, 2014

NDepend - Static Analysis Tool for .NET Managed Code

Articles Of The Day


Introduction

  • This Article shows how to use NDepend With your ASP.net MVC Application.

What is NDepend ?
  • NDepend is a static analysis tool for .NET managed code.
  • This tool supports a large number of code metrics, allows for visualization of dependencies using directed graphs and dependency matrix.
  • This tool also performs code base snapshots comparison, and validation of architectural and quality rules.
  • User-defined rules can be written using LINQ queries. This possibility is named CQLinq.
  • This tool also comes with a large number of predefined CQLinq code rules.
  • Code rules can be checked automatically in Visual Studio or during continuous integration.

Top 13 NDepend Features
  1. Code Rule and Code Query - More than 150 default code rules to check against best practices.
  2. Trend Monitoring - Get Trend Charts about pretty much any code metrics to master the evolution of your application.
  3. Harness Test Coverage Data - Import test coverage data, and make the most of it in the NDepend feature-rich context.
  4. Code Quality, 82 Code Metrics - Lines of Code, Cyclomatic Complexity, Coupling, Nesting Depth, Rank, NDepend supports them all.
  5. Explore Existing Architecture - Explore how the code is actually structured and shed light on architectural flaws kept secret.
  6. Detect Dependency Cycles - Get rid of dependency cycles between components to achieve higher code maintainability.
  7. Compare Builds and Code Diff - Compare two versions of a code base and browse code diff and changes in any way you can think of.
  8. Enforce Immutability and Purity - NDepend helps maintaining clean side-effects free code to achieve clean concurrent programming.
  9. Complexity and Diagrams - Spot too complex code at a glance thanks to unique diagramming capabilities in the .NET world.
  10. Continuous Integration Reporting - Integrate NDepend analysis into your build process and get highly customized and detailed reports to see progression and prevent code quality degradation.
  11. Warnings on Build Process Health - Be warned of potential build process problems before they end up causing friction and pain.
  12. NDepend.API and Power Tools - Write your own static analyzer based on NDepend.API, or tweak existing open-sources Power Tools.
  13. Real-World Proof - Full Visual Studio integration, .NET Reflector support, super fast and lightweight analysis, NDepend is conceived for real-world programmers.

How to Install NDepend ?

Step 1 :
  • Download the NDepend installation zip file.
  • To purchase : Buy
  • 14-day Free Trial : Free Trial

Step 2 :
  • Close Visual Studio.
  • To install NDepend, just unzip the files in a private application folder on your machine. 
  • Don't unzip files in '%ProgramFiles%\NDepend'. This will provoke problems because of Windows protection.
  • If you are running NDepend Professional Version, copy your license file in the same folder where you unzipped NDepend files.

Step 3 : 
  • Click NDepend.Install.VisualStudioAddin.exe

NDepend - Static Analysis Tool for .NET Managed Code


 
Step 4 :
  • Select your Visual Studio version and then click 'Install'.

NDepend - Static Analysis Tool for .NET Managed Code


 Step 5 :
  • Open Visual Studio.
  • You can see the 'NDEPEND' menu item on your Visual Studio main menu as shown below.


NDepend - Static Analysis Tool for .NET Managed Code


That's it.You're done.



How to Attach new NDepend Project ?

Step 1 :
  • Open Visual Studio after having installed the NDepend addin
  • Open your solution containing the code to analyze.

Step 2 :
  • Click 'NDEPEND' menu and then select and click 'Attach new NDepend Project to current VS Solution'. 

NDepend - Static Analysis Tool for .NET Managed Code

Step 3 :
  • The dialog opened has been populated with .NET assemblies of the Visual Studio solution.
  • Here you can add more .NET assemblies compiled from another solutions.
  • If you want,you can filter out the assemblies as shown below. 

NDepend - Static Analysis Tool for .NET Managed Code




























Step 4 :
  • For the simplicity of this analysis,I have selected only one assembly. 
  • Click 'Analyze a single .NET Assembly' button.The NDepend analysis start.
  • It will just take a few seconds to analyze your code base for the first time.

NDepend - Static Analysis Tool for .NET Managed Code




























Step 5 :
  • After that it pops up the below kind of dialog box.
  • From that you can select 'View NDepend Dashboard' option.
  • You can use Dashboard as an entry point to get started with NDepend.

NDepend - Static Analysis Tool for .NET Managed Code



























Let's Explore some Features of NDepend


NDepend Dashboard
  • A dashboard that shows at a glance the state of your code base and will soon become your entry point to many features.

NDepend - Static Analysis Tool for .NET Managed Code




















Focusing on Rules Violations 
  • When you click the 'Critical Rules Violated' link from the above Dashboard,It shows the screen as below.
  • It's listed all Rules Violated and categorize according to the rule types.It's really awesome.


NDepend - Static Analysis Tool for .NET Managed Code






















  • If you need to analyze further about the Rules Violations,just click the item which you want from the right side panel.
  • Matter of a second it gives all the details of that rule violation with the recommendations where how to fix that issue and more.It's simply amazing.
  • As an example,You can see that 'ValidationCreateCustomerPetsHistory' method is having 39 parameters on it.Phew ...  :(

NDepend - Static Analysis Tool for .NET Managed Code





































Nice minute Video


What is CQLinq ?
  • Code Query LINQ, is a feature proposed by the tool NDepend since the version 4, to query .NET code through LINQ queries.
  • A CQLinq query is a LINQ query that relies on types defined in the namespace NDepend.CodeModel of the NDepend.API.
  • A CQLinq query can be edited live in the NDepend UI (standalone or in Visual Studio).
  • The query is executed automatically as soon as it compiles.

The syntax is as simple as:

from m in Methods where m.NbLinesOfCode > 30 select m

  • The above query will only match large methods that are having more than 30 lines of code.
  • If you need to customize your analysis by using CQLinq,just read this CQLinq Syntax.


Visualizing Code Metrics with Treemap
  • In the Metric View, the code base is represented through a Treemap.
  • Treemapping is a method for displaying tree-structured data by using nested rectangles.
  • The tree structure used in NDepend Treemap is the usual code hierarchy.

It's like this :  
  • .NET assemblies contain namespaces.
  • Namespaces contain types.
  • Types contains methods and fields.

For Which Scenarios Treemap can be Applied ?
  • Too Big, Too Complex
  • Flaws Localization
  • Code Coverage Density
  • Top-Down Code Exploration
  • Code Structure Observations

Let's Explore one scenario with more details.

Too Big, Too Complex
  • NDepend provides many code metrics to spot too big and too complex code.
  • Method with too many parameters, too many variables, too many lines of code, too high cyclomatic complexity etc...

Step 1 : 
  • Click 'NDEPEND' and select 'Metric'.Then choose and click 'Code Metric View' sub menu as shown below.
NDepend - Static Analysis Tool for .NET Managed Code



Step 2 :
  • On the screenshot below, the Treemap Level is set to Type and the Metric is number of lines of code (LOC).
  • Large rectangles represent large types of the code base.
  • Hovering a rectangle with the mouse indicates the Type metric values, here the type number of lines of code.
  • You can see that code Treemapping helps not only spotting too large and too complex code elements, but also, it helps comparing their respective size and complexity.It's simply awesome. 
  • You can read more about Code Metrics with Treemap here.

NDepend - Static Analysis Tool for .NET Managed Code




































Do you need to Dive Deep ends of  NDepend ?


Conclusion

  • You saw that the awesomeness of the NDepend tool. It's really great tool to do the Static Analysis of .NET Managed Code.
  • I have never used NDepend before do this article. But I learned lots about this tool within a few hours of hands on practices with the project, which I'm working on. And of course I have seen lots of issues and rule violations which are existing with the project. I'll definitely inform this to my project manager and ask for time for doing the re-factoring phase. Thanks for NDepend. :)
  • You too can learn NDepend very quickly. Because NDepend's home page provides all necessary easy to learn nice videos and well written documentation. Other than that NDepend itself has a very nice Context sensitive help. Which is really awesome.
  • I would like to recommend NDepend for the .NET Senior developers as well as, of course, for the Tech Leads and Architects.
  • I must put a special thanks for Creator of this tool 'Patrick Smacchia'. He is the person who gave me this opportunity to evaluate NDepend with Free License to the product. Thanks again for you. :)


I hope this helps to You.Comments and feedback greatly appreciated.

If you feel it was a good article,Give me a +1.Thank You.




You Might Also Like

22 comments:

  1. Thanks for sharing your informative article on investing in social media marketing. Your entire blog was totally awesome. Keep on updating with such awesome information. SEO Training in Chennai

    ReplyDelete
  2. This information you provided in the blog that was really unique I love it!!, Thanks for sharing such a great blog..Keep posting..

    J2EE Training in Chennai

    ReplyDelete
  3. Awesome blog!!! Your article is very clear and gives complete overview about Search Engine Optimization and its return on investment. SEO institutes in Chennai

    ReplyDelete
  4. Agree with your thoughts. Content is considered as king of SEO techniques. After penguin update, content marketing is gaining more popularity all over the world. Thus, you need to update your site with unique, informative and engaging content. SEO institutes in Chennai

    ReplyDelete
  5. SEO Training Institute Chennai

    Your information is really useful for me.Thanks for sharing such a valuable information. If anyone wants to get SEO Training Chennai visit FITA Academy located at Chennai. Rated as No.1 SEO Institutes in Chennai.

    SEO Training in Chennai

    ReplyDelete
  6. Digital Marketing Chennai

    Thanks for sharing this informative blog. Recently I did Digital Marketing courses at a leading Digital Marketing Training Institutes in Chennai. It's really useful for me to make a bright career. If anyone wants to get Digital Marketing Training in Chennai visit infiniX.

    Regards...

    Digital Marketing Courses in Chennai

    ReplyDelete
  7. It helps the software developers and programmers to validate software application performance and behavior before deployment.Nice article.

    SEO Training in chennai | SEO Training chennai | SEO Course in chennai | SEO Course chennai

    ReplyDelete
  8. Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for Learners..
    html5 Training in chennai | html5 Training chennai

    ReplyDelete

  9. Thanks for your blog. We request for your valuable suggestions about SEO Training Course Syllabus. My friends suggested IICT Chromepet is the best SEO Training Institute in Chennai. If any other institutes are their for SEO Training in Chennai kindly please suggest me. I heard SAP Training in Chennai is good at IICT Chromepet. Thanks for spending time guys.

    ReplyDelete
  10. Thanks a lot for your information about the .Net Tool. Excellent info about .Net...
    SEO Training in Chennai

    ReplyDelete
  11. Good to learn something new about Static analysis tool from this blog. Thanks for sharing such worthy article. By SEO Course in Chennai

    ReplyDelete
  12. Hello , I have been training students on AngularJS for past 6 months, and at times, I have used your blog as reference for the class training and also for my personal project development. It has been so much useful. Thank you, keep writing more:)
    AngularJS training institute in Chennai

    ReplyDelete
  13. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:
    Oracle Training in Chennai

    ReplyDelete
  14. In recent days Angular plays vital role to loading your site content in a fastest way, so it’s a required skill for everyone, thanks for sharing this useful information to our vision keep blogging.
    Regards,
    Angularjs training in chennai|Angularjs training chennai|Angularjs course in chennai

    ReplyDelete
  15. The content of your blog is really interesting. I like this content and was very informative. If you are interested in taking SEO as your professional carrier visit this website.
    SEO Training in Chennai

    ReplyDelete
  16. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  17. I am reading ur post from the beginning, it was so interesting to read & i feel thanks to you for posting such a good blog, keep updates regularly.Best Hadoop Training Institute In Chennai

    ReplyDelete
  18. Really interesting content which is interesting and provided me the required information.
    SEO Training in Chennai | SEO courses in Chennai | SEO training Chennai | SEO institutes in Chennai

    ReplyDelete
  19. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Hadoop Training Chennai | PHP Training in Chennai

    ReplyDelete

Thanks for your Feedback.