Skip to content

Understanding the output

Understanding AST Metrics

You don't need a PhD in Computer Science to use AST Metrics, but understanding a few concepts will help you get the most out of it.

1. Everything is a Tree (AST)

First, you need to understand that any source code can be represented as a tree. This tree is called an Abstract Syntax Tree (AST).

For example, this code:

while b  0:
    if a > b:
        a := a - b
    else:
        b := b - a
return a

Can be represented as this tree:

Wikipedia
The AST of the code, from Wikipedia

AST Metrics analyzes this tree to calculate complexity, volume, and other code-level metrics.

2. The Architecture is a Graph

Just like code forms a tree, dependencies between your files form a graph.

  • When Class A uses Class B, there is a link.
  • When Class B uses Class C, the chain continues.

AST Metrics analyzes this graph to find:

  • Communities: Groups of classes that work together.
  • Cycles: Circular dependencies that lock your system.
  • Coupling: How tightly connected your components are.

3. From Math to Insights

By combining the AST analysis (micro-view) and the Graph analysis (macro-view), AST Metrics uses mathematical models to uncover hidden truths about your project:

  • Bus Factor: Who is indispensable?
  • Risk: Where are bugs likely to hide?
  • Architecture Violations: Where is the code not doing what you think it is?