Partners: KDAB Whole Tomato Software CppDepend

23 November 2014

3 Tools to Understand New Code from Visual Assist

You’ve just started a new job and landed in front of a huge code base. Great! What a challenge! It would be nice to quickly get a general understanding of your project and be able to comfortably move around in the code. How do you do it?

In the article you can find my list of three set of tools from Visual Assist that might help with this problem.

The plan

Promotional note

I got a free copy of VisualAssistX for writing the text from Whole Tomato Software. Still, opinions expressed here are my own and comes from everyday use of this product. The idea of this blog post is also mine. I recommend VA because it helps me a lot during normal development work.

This text appeared also on Whole Tomato Software blog: Tomato Soup

VisualAssistX briefly

VisualAssistX (VA) from Whole Tomato Software is a very well known, popular and powerful productivity addition to Visual Studio. VA supports most of Visual Studio versions (even VC6.0!).

Some of the features:

  • Works with C++ and C#
  • Refactoring options for native code!
  • Code Generation
  • Debug Assistance
  • Code Snippets
  • Enhanced Syntax Coloring
  • Can support Intellisense and is usually much faster.

Full list can be found here.

You can download the free 30-day trial and have a quick look: Download a free trial.

The list of tools

As an example project, let’s take a look at Irrlicht Engine.

Go To

Feature that I use probably most often is definitely "Go To". In short, it is an improvement for a very well known tool from Visual Studio - "Go to definition/declaration". But, we all know how this works (or actually doesn't work) in VS. Sometimes you have to wait for a response from VS or simply you cannot move anywhere...

This time, with Visual Assist X, you get a really nice working version of the tool: just press "Alt+G" (the default keyboard shortcut), select where you want to go and VA will do it immediately!

This is especially useful for:

  • You are reading some kind of a class interface and you want to go to implementation of some method. You can take a glace of the internal code and then quickly go back to the interface.
  • You want to check declaration of a variable. Use "Go To" to see where this is declared (is it a local variable or maybe a member of a class).

Go To, Example

I am in IParticleEmitter.h and I see class IParticleEmitter interface declaration. There is an interesting method called emitt(...) - how it's implemented?

I can use "Go To" and then I get the following result:

Of course VA sees that a method can have multiple polymorphic implementations. It allows to select the desired implementation and jump into it. In the list you can move via arrow keys, mouse or assigned numbers/letters keys.

Now I' am in the implementation of this method: CParticleBoxEmitter::emitt, there is some code:

if (MaxAngleDegrees)
{
    core::vector3df tgt = Direction;
    tgt.rotateXYBy(os::Randomizer::frand() * MaxAngleDegrees);
    tgt.rotateYZBy(os::Randomizer::frand() * MaxAngleDegrees);
    tgt.rotateXZBy(os::Randomizer::frand() * MaxAngleDegrees);
    p.vector = tgt;
}

What is this MaxAngleDegrees? Is it a static constant or a class member? I can hove my mouse over it and get some basic information, but via "Go To" I can go to the place where it is defined, so I can see some more context.

When I want to return (to the interface that I was looking at initially) I can use several ways:

  • "Ctrl + Tab" - just go to the previous window
  • "Ctrl + -" - go to a previous location
  • Navigate Back Visual Assist command (that will be described separately)

Hint:

Additionally, "Alt+G" works in other situations as well: for instance press it when the caret is in a line with the #include "#xyz" statement. You will simply move to this file!

Go To Related

Visual Assist went even further with the implementation of "Go To". If you use "Shift + Alt + G" you will see much more advanced version of the tool.

For instance:

Now I can see base classes, derived classes and even go to a particular member!

Find All References

With "Go To" we can switch from declaration to implementation smoothly. This works, but unfortunately, life is not that easy :) Usually, when we see an interesting variable or a function we would like to see not only its declaration or implementation, but how and were is it used.

Previously we were curious about MaxAngleDegrees from CParticleBoxEmitter.cpp. We know than it's a 32 bit integer variable used to generate rotations. Where it is actually initialized?

Just press Shift + Alt + F (Find References default keyboard shortcut) and you will see something like this:

Above there is a list of places where our variable is used. It seems that the variable is loaded from a settings file.

This is, of course, nothing special - Visual Studio has similar feature. But, with Visual Assist we have some more benefits:

  • You can see a context of the particular line - tooltips.
  • Read/Write references can be selected
  • As with most Visual Assist tools: it works faster than Visual Studio. Also, I've found that the results are a bit more narrow.

We can extend our search and go further:

  • MaxAngleDegrees is deserialized in CParticleBoxEmitter::deserializeAttributes
  • This method is called from CParticleSystemSceneNode::deserializeAttributes
  • It's also polymorphic and might be called from CSceneLoaderIrr::readSceneNode
  • ...

That way we can even track the whole system of loading scene nodes. We can now see the flow of this functionality. Without "Find" it would be very problematic.

Hint: You can also use "Find References in File" to, as name suggest, see references to a symbol in file you are actually in.

Find Symbol in Solution

Finding references for a given symbol is very useful, but what if you do not know the exact name? Maybe you just have some basic idea of what you want to find?

For instance in Irrlicht Engine we want to see implementation and an interface of some manager? A scene manager, for instance. "Find all references" would not work this time. You can use normal "search" box, but you might end up with too much symbols and lines to check.

In this case you can use "find symbol" (Shift + Alt + S, by default) tool. It will show you a dialog box will all the symbols from the current solution (or even third party libraries)!

As you can see above "manager scene" is related to several different classes. We can select the most interesting object and go to its definition. The list enables to narrow the search results much quicker than in a normal "search box".

Additionally you could use some more advanced options: like searching only in classes (this will skip defines and free functions) or extend your search to files outside your solution.

This tool is definitely much more convenient that the common search dialog.

Moving

When you see a lot of new code, and lots of new files... for sure, you will need to jump between different code locations. One of the most frustrating thing is when you look a the code, then move to some other place (to see some internal implementation for instance) and then try to go back to the initial place. In a large project it's not that easy to just "remember" location by yourself.

Quick solution might be to use Ctr+Tab and switch between recent files. But what if you are in a file with 10k lines of code and you want to go back to a previous position in the same file?

Fortunately, In Visual Studio there is a great feature: "move to previous/next location". It remembers you history and lets you move much quicker between locations.

By default you can use "Ctrl + -" to go back and "Ctrl + Shift + -" to go forward.

What does it record? Actually most of you movements: file change, caret navigation, goto definition/declaration, find reference, find in files.

One problem: if you are unlucky and you work with VC6.0 then you will not have this feature at all. Simply use Visual Assist instead. Additionally, since Visual Studio might have a different implementations of navigation in each version, you can use Visual Assisy to have a consistent tool that works in the same way across all VS versions.

Additional tools

Beside all the tools already described there are others that might help you with better code understanding:

Enhanced syntax coloring

Without syntax coloring coding would be much slower - no need to verify that. But Visual Assist went even further. Now, we can see much more. Below there is a comparison between VS2008 default coloring and Visual Assist's style:

Visual Assists have separate colors for classes/structures/types, variables, preprocessor macros and methods. Additionally, so called "stable symbols" (like function names from third party libraries) can be displayed in italic - look closer at QueryPerformanceFrequency call, for instance.

That way it's not just black colors for most of the code.

VA view

This is a handy tool that joins several functions at once:

  • you can type name of a file in a solution and quickly go to that file
  • you can find symbols in a solution
  • you get a LRU list so that you can quickly go to previous symbols or files
  • when you are in some code VA View will show methods/symbols related to the code. In the picture you can see that it shows SParticle members - because we are close to this class.

Learning curve for VA view is a bit longer than for commands that I mentioned previously. But, I think it is worth to test the tool and decide if it adds some value to our productivity or not.

Summary

In the series I tried to show you what to do when you land in front of a completely new code base. Visual Studio (like every other modern IDE) has some standard methods that might help you. Still I advice to use Visual Assist that goes beyond: not only it has better performance but offers much more options:

  • With Goto tool you can quickly switch between declaration and implementation of a given symbol. Use it for going to implementation of an interesting function/method, or when you want to find where is a variable declared. You can even open header files with that. One of the most powerful (and easy to use) feature.
  • Find options allows you to discover a "flow" in the project. Just follow the interesting symbol: find where is it called from, what are other references.
  • And finally use navigation buttons to go back (or forward) in your code history.

Learn More

You can learn more about the Find commands in the documentation for Visual Assist:

Get my free ebook about C++17!

More than 50 pages about the new Language Standard.

C++17 in detail, by Bartlomiej Filipek

For now I don't have my own courses, but I promote others :) (Warning: I'll also get a little commission for every signup). Have a look my recommended C++ courses at @Pluralsight (more info in my Resource page):

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.