Tips and Tricks

Tools to understand new code: Go To

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 my series of articles as a guest contributor to this blog, you will learn about my favorite Visual Assist tools that help with code understanding. My tools are:

  • Go To
  • Find
  • Move
  • Additional tips

In this post, let’s take a look at Go To functionality.

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

Go To

The feature in Visual Assist that I probably use most often is 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 go anywhere.

With Visual Assist, 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 Visual Assist will go to it immediately!

Alt+G is especially useful when:

  • You are reading a class interface and you want to go to the implementation of some method. You can take a glance at the internal code, then quickly go back to the interface.
  • You want to check the declaration of a variable. Use Go To to see where the variable 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 the class IParticleEmitter interface declaration. There is an interesting method called emitt(...) — how is it implemented?

I can use Go To and get the following result:

goto_iparticleemit

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

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 hover 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 do it in several ways:

  • Ctrl+Tab to go to the previous window
  • Ctrl+- to go to the previous location
  • Navigate Back — a Visual Assist command that I will describe in another article

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

Go To Related

Visual Assist goes even further than Go To with the implementation of another commend — Go To Related. If you use Shift+Alt+G instead of Alt+G, you will see a much more advanced version of Go To. For instance:

goto_related_iparticle

With Shift+Alt+G, I can see base classes, derived classes and even go to the definition a particular member!

Summary

Go To  and its related commands, Go To Related and Go To Member, are some of the most important tools in Visual Assist. The Go To commands enable us to move in the code quickly and jump among definition/use/declaration. The implementations in Visual Assist are very advanced and more efficient that the native Visual Studio solution.

Learn More

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

This article was contributed by Bartlomiej Filipek, who writes at Code And Graphics — a technical blog about C++ and OpenGL.

Leave a Reply

%d