ndepend

How to compute the metric Response for a Method with NDepend


Is there any way to get the number of "source code lines" that could result from calling nested function?

For this question my example:

Selection of functions

Function name Lines of Code (LOC) [function body]
Function1 10
Function2 20
Function3 20

Example 1
Function1
...|-> calls Function2
......|-> calls Function3
Sum of LOC= 50

Example 2
Function1
...|-> calls Function3
......|-> calls Function2
Sum of LOC= 50

Example 3
Function1
..|-> calls Function2
..|-> calls Function3
..|-> calls Function2
Sum of LOC= 70


Solution

  • Here is a code query that computes the Response for each method of a code base:

    from m  in Application.Methods
    
    let methodsCalledMetric =
       m.MethodsCalled.FillIterative(
           methods => methods.SelectMany(mm => mm.MethodsCalled))
    
    let methodsCalled = methodsCalledMetric.DefinitionDomain
    
    let responseLoc = methodsCalled.Sum(mm => mm.NbLinesOfCode)
    
    select new { m, methodsCalled, responseLoc } 
    

    The result looks like:

    NDepend code query for response for a Method

    The set of methods called by any method can be either listed (by clicking the 136 methods cell for example) or exported to the dependency graph to visualize it in a clearer way:

    call dependency graph produced by NDepend