NDepend

NDepend is a static analysis tool for .NET managed code. The tool supports a large number of code metrics that allow one to visualize dependencies using directed graphs and dependency matrix. The tool also performs code base snapshot comparisons, and validation of architectural and quality rules. User-defined rules can be written using LINQ queries. This feature is named CQLinq. The 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.

NDepend
Developer(s)NDepend
Stable release
2020.1.0
Operating systemWindows
TypeSoftware quality
LicenseCommercial, Proprietary
Websitendepend.com

Features

The main features of NDepend are:

  • Dependency Visualization (using dependency graphs, and dependency matrix)
  • Software metrics (NDepend currently supports 82 code metrics: Cyclomatic complexity; Afferent and Efferent Coupling; Relational Cohesion; Google page rank of .NET types; Percentage of code covered by tests, etc.)
  • Declarative code rule over LINQ query (CQLinq)
  • Integration with CruiseControl and TeamCity
  • Optional code constraints in the source code using CLI attributes
  • Version comparison of two versions of the same assembly

Code rules through LINQ queries (CQLinq)

CQLinq editor and query result displayed

All recent versions of the tool (after V4) provides live code queries and code rules through LINQ queries. This is one of the main innovations of NDepend. For example:

  • Base class should not use derivatives:
 // <Name>Base class should not use derivatives</Name>
 warnif count > 0 
 from baseClass in JustMyCodeTypes
 where baseClass.IsClass && baseClass.NbChildren > 0 // <-- for optimization!
 let derivedClassesUsed = baseClass.DerivedTypes.UsedBy(baseClass)
 where derivedClassesUsed.Count() > 0
 select new { baseClass, derivedClassesUsed }
 // <Name>Avoid making complex methods even more complex (source code cyclomatic complexity)</Name>
 warnif count > 0 
 from m in JustMyCodeMethods where
  !m.IsAbstract &&
   m.IsPresentInBothBuilds() &&
   m.CodeWasChanged()
 let oldCC = m.OlderVersion().CyclomaticComplexity
 where oldCC > 6 && m.CyclomaticComplexity > oldCC 
 select new { m,
     oldCC, 
     newCC = m.CyclomaticComplexity, 
     oldLoc = m.OlderVersion().NbLinesOfCode,
     newLoc = m.NbLinesOfCode,
 }

Additionally, the tool provides a live CQLinq query editor with code completion and embedded documentation.

See also

NDepend reviewed by the .NET community

Books that mention NDepend

  • Girish Suryanarayana, Ganesh Samarthyam, and Tushar Sharma. Refactoring for Software Design Smells: Managing Technical Debt (2014)
  • Marcin Kawalerowicz and Craig Berntson. Continuous Integration in .NET (2010)
  • James Avery and Jim Holmes. Windows developer power tools (2006)
  • Patrick Cauldwell and Scott Hanselman. Code Leader: Using People, Tools, and Processes to Build Successful Software (2008)
  • Yogesh Shetty and Samir Jayaswal. Practical .NET for financial markets (2006)
  • Paul Duvall. Continuous Integration (2007)
  • Rick Leinecker and Vanessa L. Williams. Visual Studio 2008 All-In-One Desk Reference For Dummies (2008)
  • Patrick Smacchia. Practical .Net 2 and C# 2: Harness the Platform, the Language, the Framework (2006)
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.