Visual C++ is one of the most used C++ IDEs which provides many interesting features to developers, each new version brings new major features and many extensions are available to add more nice features to it.In this post, I will talk about some useful features provided by CppDepend.
Visualize your Code Base
Dependency Graph
The dependency graph is the most common used graph to represent the dependencies between code elements, Visual Studio provides an interesting one. And the Graph provided by CppDepend is more oriented code quality, indeed the box size as the Edge thickness could be proportional to one of many metrics available.
Dependency Matrix
The DSM (Dependency Structure Matrix) is a compact way to represent and navigate across dependencies between components. DSM is used to represent the same information than a graph, but it’s more practical if:
- Many code elements are involved.
- You need to discover the dependency weight between elements.
- Discover easily dependency cycles between code elements.
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 is the usual code hierarchy:
- C/C++ projects contain namespaces
- Namespaces contain types
- Types contains methods and fields
The rectangle size is proportional to the metric you choose, by default it’s the NbLinesOfCode
. And the Metric View can display a second metric by coloring the treemap elements. Hence two code metrics can be displayed at once.
For example, in this treemap, the rectangle size corresponds to the lines of code and the color to the cyclomatic complexity, you can visually detect where are the most complex method and the biggest ones.
Metrics Info
Many metrics are available for projects, namespaces, classes, methods and fields. The info view report some of these metrics which is very helpful to check in dev the quality of our implementations.
Define Rules
CQLinq is maybe the most powerful feature provided by CppDepend, we can easily define some advanced queries to search for a specific code elements. The CQLinq editor has many nice features to help us create our custom rules and the result is calculated in real time.
Get Diagnostics
With CppDepend, you can easily get all Clang, Cppcheck and Vera++ issues. You can plug other tools using the API.
Trend Charts
Trend chart is a useful feature to explore the evolution of a metric after some code changes. Many charts are provided by default and you can easily create your own charts.
Advanced Search
Sometimes, it’s useful to search methods by their code size, cyclomatic complexity, comment percent, coupling,…
The CppDepend provides this feature and you can search for code elements using many metrics.
Conclusion
CppDepend could help you to better understand your code base and detect some implementation and design flaws. However, as mentioned before, its feature richness makes it not easily accessible after a first use, you have to spend some hours to master some of its capabilities.