Easy C/C++ Source Code Analysis with Visual CppDepend

Share

For the past few weeks I have been quite busy working on a couple of things which involve quite a lot of coding. I had gotten myself a copy of CppDepend and knew this was the time to put it through the trenches. CppDepend is a static code analysis application that simplifies managing very complex C/C++ code through analysis of the code dependencies on Windows through visualization and the use of CQL (Code Query Language).

At first I did not know what to expect out of CppDepend but after a few minutes of using it to analyze my C/C++ source code, I found myself extremely pleased with the results. CppDepend is something I think every C/C++ developer should invest in as it gives you a new insights into your code better than before. CppDepend can be one of the keys that make C/C++ languages the ones that you fall deeper in love with.

CppDepend has an intuitive user interface that you can easily and quickly get settled into. With CppDepend as your source code analysis tool, you can find bottlenecks and redundancies and other metrics in your code that include but not limited to:

  • Lines of Code
  • Lines of Comments
  • Percentage of Comments
  • Number of Projects in your Solution
  • Number of Namespaces
  • Number of Types
  • Number of Methods
  • Number of Fields and so on.

Included in CppDepend is a class browser that you can use to view the details of your code such as viewing the internal dependencies of the class and the methods within that class. Other information is also available to you such as the lines of code of the class and the individual methods. The Cyclomatic complexity of the methods, depth of inheritance, number of children and types used from within and external projects.

The results of the analysis on your C/C++ source code that CppDepend does can be viewed visually using either the dependency graph, the dependency matrix or the metrics view.

CppDepend Dependency Graph

CppDepend Dependency Graph

CppDepend Dependency Graph

When using the dependency graph, the different nodes that represent the projects or classes can be displayed in different colors to display which project depends which, or which project is used by which other and so on. In the event that the dependency graph appears to be too complex, there is an alternative way to view the dependencies. This can be achieved by using the dependency matrix.

CppDepend Dependency Matrix

CppDepend Matrix

CppDepend Matrix

The dependency matrix in CppDepend will give you a 2D view of your projects with color coded coordinates labels with literals that allow. The colors in the coordinate squares represent how the project in the column is related to the project in the rows. The number inside each square represents the methods involved in the coupling. You can further drill down and get more intricate details by double clicking on a desired square.

CppDepend Metric View

CppDepend Metrics

CppDepend Metrics

The CppDepend Metric view is a treemap of rectangles with the parent rectangles representing the different projects in you application. Each little rectangle in the metric treemap represents a different method portraying the number of lines of code by using proportionally sized rectangles. The treemap easily helps to spot patterns in you code that would be too difficult to visualize in any other way. This metric view is ideal when using it to visualize the result of the CQL operations.

Code Query Language (CQL)

CppDepend CQL Editor

CppDepend CQL Editor

This is a powerful tool with obvious roots form Structured Query Language (SQL). CQL is easy to use and ideal as a filter when it comes to deeper analysis of your C/C++ source code. You can use CQL through the CQL Query Editor. This powerful language helps your search and manage your code using preset criteria including but not limited to Cyclomatic Complexity, code was changed, is constructor, is constant, lines of code exceeding a certain figure and many more. Rather than listing the whole list here is is only wise to get CppDepend and see for yourself.

The great thing about using CQL is that the built-in CQL Editor comes with a comprehensive code complete feature that can help you build up your queries without a though to it. I just need to point out that the keywords used in the CQL editor should be typed in uppercase letters for the code complete to function as expected.

As you use the CQL editor it is awesome to note that the results are in real-time. No waiting! You can change parameters on the fly and see the results appear as you type alone. Writing a CQL Query such as:

SELECT TOP 10 METHODS WHERE NbLinesOfCode > 50

would yield immediate results. Obviously. Now below the 50, a slider would appear covering the lines of code range of all the methods. You can easily slide this along to see the different methods increase and decrease in real-time.

Clear Benefits of CppDepend

So what are the benefits of CppDepend C/C++ source code analysis tool? If you are writing a simple “Hello World” program then CppDepend is probably not for you. This C/C++ source code analysis tool is especially useful for those with large, medium and yes, even smaller software application projects. Whether you are working in a team or as an individual you will find the results of the analysis mind blowing.

You can easily eliminate redundant code from searching out projects, classes or structs, methods and types that have no other objects or ode depending on them. You can check out your percentage of comments in the code to determine the quality of your naming and whether you need more or les comments in you code.

With CppDepend you as a C/C++ programmer will be able to easily track down methods that have gotten way too complex or too large and come up with a way to break them down into simple methods with fewer lines of code. A source code base with a couple hundred lines of code can be re-factored manually quite easily. When you have 402,711 lines of code like the one I am working on, or even millions of lines of code. you begin to learn things about your code that you did not know about you code and you get to appreciate what CppDepend can do for you.

CppDepend can also be installed as a plugin into Microsoft Visual Studio.

You can get yourself a trial version of CppDepend here and make a decision to purchase the full pro license.

To learn more about Sobbayi Interactive’s services or to find out how to get your very own custom applications for your business developed by our super-talented team, email us today at info@sobbayi.com or get started here.

Related Posts:

  • Back to Portfolio
  • 0 comments on “Easy C/C++ Source Code Analysis with Visual CppDepend
    2 Pings/Trackbacks for "Easy C/C++ Source Code Analysis with Visual CppDepend"
    1. [...] some time now CppDepend the Windows based C/C++ code analysis software has been made available for free for C/C++ open [...]

    2. [...] few days ago we discussed how you can Analyze your very large and complex C/C++ code base using CppDepend on your Windows development platform. Part of the process involved the use of Code Query Language [...]

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Tips

    We can get your business running efficiently with our customized software applications which will get you way ahead of the competition at a fraction of the cost

    Testimonial

    "The Sobbayi team was really patient as they worked to get my rich presentation just right to work on new and very old hardware alike. Thanks guys"

    Marcos Garcia