Improving Visual Assist: We need your opinion

Good day! The Whole Tomato team is looking to improve the Visual Assist experience in other fields, and we are inviting you to join us!

We are currently looking for focus group participants in the financial service sector. Eligible participants include programmers or people working in similar positions in banking, investment, trading, insurance, and similar sectors. 

Specifically, we are looking for those using C++ in their work— perhaps for high-performance trading, insurance calculations, payroll organization, or anything at all so long as it’s C++.

If you think you fit these requirements, please fill out this form.

Participants who attend the focus group sessions will be awarded with a visa gift card, and will be given special privileges as a token of our appreciation.

Long-time users will remember how VAX started as a simple plugin that provided code snippets, code refactoring, and file navigation. Newer users may be aware of VAX’s seamless integration for Unreal Engine projects, which is arguably one of our most successful features—though perhaps not widely used in finance. Today, our latest achievement comes with the release of our official support for Visual Studio 2022— more on that here

Just as we are a key tool for game development using Unreal Engine, we want to help those who use C++ in finance— and that’s where this focus group comes in.  We want to invite our community to influence Visual Assist’s development as we head into this new venture. The future awaits, and we hope you are as excited as we are.

Visual Studio 2022 Support!

Hello! We have very good news today. We just released Visual Assist 2021.5 and it has our official support for the Visual Studio 2022 release.

This blog could be as short as that sentence, but I’d like to write a bit more about our support and how we got here. Meanwhile I recommend if you’re using VS2022 you download and install 2021.5 now!

Background

Historically it’s been very important to us to release support for new versions of Visual Studio very quickly, and if you’ve read our blog posts this year about VS2022, you’ll have read me say that before. While many customers stay on older versions for some time, we have a lot of people who upgrade immediately, so we’ve always put a lot of emphasis on being able to ship a version of Visual Assist supporting new versions of Visual Studio quickly. While I’ve been product manager here for almost three years, this is the first new major version of Visual Studio during that time, and I and the whole team were keen to continue that speedy-support tradition.

We started work supporting VS2022 early, and we’ve shared our progress over this past nine months about the work we’ve been doing to support VS2022, with beta support for Previews 3, skipping 4 due to a breaking bug, and 5, 6, and 7/RC. We released Visual Assist 2021.4 shortly before Visual Studio 2022 was released, and many of you are using it with VS2022 already.

Visual Studio 2022 was a large change from previous versions. Not only did it change to 64-bit, but there are many new APIs as well, and these APIs change the interaction model from synchronous to asynchronous interaction. This is a pattern Visual Studio has been following for several years (and we encourage it—it really helps the IDE) but as you may know migrating from any sync to async model is rarely trivial. Usually, the majority of the work for each new Visual Studio release is around adapting to API changes, and that was the case here too. In fact, the most major bug we saw using Visual Assist (abbreviated VAX) 2021.4 with VS2022 and which was one of the issues we fixed for today’s official support, an issue where the code suggestions window sometimes did not show in the right place, was related to the move to one specific async API.

Timeline

  • We released Visual Assist 2021.4 on October 29.
  • Visual Studio 2022 was released on November 8, nine days later.
  • VAX 2021.4 overall worked pretty well with the final VS2022 build
    • But both we and some customers found a few more issues, and we’ve spent the past two weeks since VS’s release resolving them
  • VAX 2021.5 with official support for Visual Studio 2022 was released on Nov 22!

Official Support for VS2022

Yesterday afternoon US time we posted Visual Assist 2021.5 on our website. We have a rolling release mechanism and in about a week you should see in-IDE notifications about the new release, followed a couple of weeks later with the new version being available in the Visual Studio Marketplace. However you can directly download and install it now.

We’ve been working on VS2022 for something like nine months now and we’re really happy to have Visual Assist publicly available with Visual Studio 2022 support. We hope it is useful to you!

A note of thanks: VS2022 was a large change from previous versions, and Microsoft has been very open and helpful. We’re very grateful to them for their communications with us, the beta program, and their assistance while we’ve added support. Thank you!

I want to note as well that though as PM I get to write these posts, I really do very little, and all the credit for this release and VS2022 support goes to our amazing team. Thank you!

Visual Assist 2021.4 is released! (And notes on Visual Studio 2022)

We are pleased to have just released Visual Assist 2021.4. VAX uses a rolling release mechanism, so it will be a couple of weeks until VAX notifies you in-product and a couple more before it’s available on the Visual Studio store, but you can download Visual Assist 2021.4 today from our website.

VAX 2021.4 is a quality-focused release. Our last release, 2021.3, was mostly focused on supporting the upcoming Visual Studio 2022 Previews. That early work on support for VS2022 means that when the official release of VS2022 is out, we’ll be able to ship official support very fast. (More on this below.)

However, not everyone upgrades to a new Visual Studio release immediately — in fact many people have very good reasons for staying on older versions for quite some time! — and we want to focus on providing what all our customers across many versions need. (We still support VS 2005!) That’s the focus for this version. This release, as a quality release, focuses on fixing bugs and adding changes for everyone.

Our release notes contain full info, but some notable changes include support for the new External Include Directories property in Visual Studio, and updating the Code Inspection engine to LLVM/Clang version 12.0.1. There are a plethora of bug fixes as well. All up we feel this release is a solid update for you no matter which version of Visual Studio, and for all ways that you use Visual Assist.

Visual Studio 2022

Swiftly supporting new versions of Visual Studio is very important to us, because we understand it’s important to many of you, and we hope you’ve enjoyed seeing VAX working in many of the Visual Studio 2022 Previews. We expect VS2022 to be released very soon. In fact, as we were preparing this release, Previews 5, 6 and 7 came out, the pace increasing so fast that our installer only mentions support for Preview 6, but we do in fact support Preview 7 as well. At the same time we’ve seen significant stability improvements with each newer preview.

We don’t want to delay our release schedule to wait until VS2022 is shipped, especially because this release is focused on what customers using other versions need, which is why we’re releasing now. But since VS2022 will be released so soon, and since we are very ready for that to happen, you can expect a swift mini-update from us adding official support.

In other words:

  • VAX 2021.4 supports Visual Studio 2022 Previews 5 and 6 (with issues leading to hangs), and 7/RC3 (fully)
  • We’re eagerly waiting for VS2022 to be released, and we’ll add official support for it very quickly when it’s out
Visual Assist 2021.4 running in Visual Studio 2022 Preview 7 (Release Candidate 3)
Visual Assist 2021.4 running in Visual Studio 2022 Preview 7 (Release Candidate 3)

We recommend you install Visual Assist 2021.4 now, and we look forward to shipping official support for Visual Studio 2022 very soon.

Visual Studio 2022 preview version 4 support

Just a quick note to let you know that we are aware of a blocking issue while using the latest version of VA in Preview 4. We offered initial beta support for 3.x, however we do not recommend installing Visual Assist on the latest preview as the hangs will render the IDE unusable. We’re working on it and hope to have an update out soon.

Even though each release offers new challenges and setbacks we’re excited for the move to 64bit and the future of Visual Assist when VS 2022 is fully baked. Thanks for your patience!

Visual Assist support for Visual Studio 2022 Previews!

Visual Assist support for Visual Studio 2022 Previews!

There’s a lot of interest in the developer community about the new version of Visual Studio, which is in preview currently. This week we released Visual Assist 2021.3 (build 2420), and Visual Assist includes beta support for the Visual Studio 2022 Previews.

VAssistX menu open in the Visual Studio 2022 Extensions menu
Visual Assist 2021.3 running inside Visual Studio 2022 Preview 3

Visual Studio Preview

Visual Studio (VS) 2022’s main change—and it’s a significant one—is that it will become a 64-bit process. Since Visual Assist (VA or VAX) runs as a plugin, in-process, we needed to build a 64-bit version of our plugin DLL. Those who have upgraded 32-bit code to 64-bit code before know that, even in well-architected code, it takes some work even just to review code to ensure it is correct. In addition, the new version adds and modifies a number of APIs we rely on to interact with the IDE. Adapting to those was the most significant change for us.

We’ve tested fully against VS 2022 Preview 2, and in fact the installer says ‘Preview 2’. There are some known regressions:

  • VA Quick Info not appearing when triggered by keyboard in VS 2022 [case: 146063]
  • Source Links example plugin does not load in VS 2022 [case: 146012]
  • Changing from Cascadia to another font for italicized system symbols requires restart in VS 2022 [case: 145979]
  • plus a few others.

Visual Studio 2022 Preview 3 was released two days ago—overlapping timing with our release—and our regression tests are showing some failures. Currently we believe those are because of changed behaviour in a Visual Studio API which we use when verifying in-IDE behaviour (ie not an issue in VAX itself), but it is always possible that once that is resolved further test failures will need to be resolved. However, we believe the current build is well worth trying out on Preview 3 as well.

Performance

Many of our customers strain the Visual Studio IDE, with many plugins and SDKs installed. Both to help them, and because we believe it’s part of being a good member of the Visual Studio ecosystem where our plugin sits alongside others, last November we greatly reduced the in-process memory usage largely through (spoiler: the full blog is worth reading) use of memory-mapped files.

Now that Visual Studio 2022 is a 64-bit process, that work is not necessary for VS2022. For older versions of Visual Studio, those techniques are still used, so if you’re using VS 2019 or even VS 2005 with Visual Assist 2021.3, you’ll still benefit from the lighter memory impact within the IDE.

When we did that work, we also focused on performance to ensure that the changes to memory access had either zero or a positive impact. The blog notes that for heavy usage, we had equal performance; for small projects, VAX actually was a bit faster. Despite no longer needing the memory usage code we added, VS 2022 benefits from that performance work as well, plus some more work we’ve done while adding support. Since it’s a beta build, and Visual Studio itself is in preview, we do not have hard numbers. But a rough guideline is that an operation like Find References that previously may have taken (say) two minutes will now take about one minute twenty seconds, or about two thirds the time.

Overall

It’s historically been very important to us to have swift support for new versions of Visual Studio, and this work is our foundation for quickly officially supporting Visual Studio 2022 when it is officially released. While the main focus of this release was VS 2022 support, there are other changes as well in 2021.3, which we’ll document in the What’s New. We know we have many customers using older versions of Visual Studio, and as well as those improvements today you can look forward to further improvements focusing on other, non-VS areas as we switch back to a more normal focus in our next release.

We’re really happy to be able to ship beta support for the Visual Studio 2022 previews, and providing an even faster Visual Assist is a happy bonus. We’ll continue to work and look forward to shipping full support when Visual Studio publishes its final release.

Visual Assist 2021.3 is available for download on our website now, and will be on the Visual Studio Marketplace in a few days. Enjoy!

Unreal Engine ‘Quality Of Life’ in Visual Assist 2021.2

Unreal Engine ‘Quality Of Life’ in Visual Assist 2021.2

The first two releases of Visual Assist this year contain some great Unreal Engine quality-of-life improvements you may want to take advantage of.

While we’ve always announced features in our changelog and release blogs, we’re starting to blog in greater detail about some of what we change — our December blog about reducing memory usage started this — and this time we’ll dig a bit more into two changes improving using Unreal Engine with Visual Assist.

This applies only to versions 2021.1 and 2021.2, the first two versions this year. If you’re reading from the future, there’s likely much more for UE than is described here!

There are two notable items in these versions:

  • Improving parse times for Unreal Engine projects
  • Removing unwanted generated headers and symbols

These mean that your Unreal Engine projects should be fully usable with Visual Assist faster when you open them, and that Visual Assist only shows and uses methods and other symbols that you’re really interested in.

Parse Times

When a solution is opened in Visual Studio, Visual Assist (VAX) parses that solution. This generates the databases of symbols and other data which VAX uses to be able to implement features like GoTo Related, extra syntax highlighting, parameter info, and so forth.

Parsing can take time. Although VAX is not based around a C++ compiler (one of its strengths), parsing is analogous to compiling a project, and while you can use VAX right away, some features require that data before they will work. Unreal Engine solutions can be very large. Therefore, we spend a lot of thought on how to speed up parse time to make the time between opening a solution and having VAX fully functional be as short as possible.

Avoiding Unnecessary Parsing

This following is going to sound ridiculously simple, and it is. What’s the best way to spend less time doing something? Not to do it.

We do focus on optimisations; the parse engine is heavily multi-threaded; the database uses considerably less memory than it used to; and other techniques. But ultimately, the best way to reduce parse time is to do less parsing.

Unreal Engine projects include plugins. These are additional libraries that add features to your game or project (in-editor or at runtime.) The UE editor lets you enable and disable these, so it’s common to have several installed but only use a subset of them. Yet, the presence of plugins is a key item that makes parsing a UE project lengthier. We added an option to turn off parsing them.

In 2021.1 we added an option to disable indexing these plugins. When off, the default, UE plugins were not parsed.

However, we realised this was based on a flawed understanding: that if plugins are third-party (as plugins often are) then you may not need them to be parsed into VAX’s memory: after all, we thought, you’re unlikely to do a ‘find references’ on an internal method of a third-party library. Omitting them from being parsed would not affect day to day use of Visual Assist. But we got feedback that it was more common than we thought for plugins to be first-party: that is, for UE developers to move parts of their game or project’s functionality into a plugin. That means that it was necessary to parse some plugins, and so a simple on/off parse all-or-none toggle was not useful.

In 2021.2 we expanded the setting so that Visual Assist can parse plugins that are genuinely used by your project, only. Today the ‘Index Unreal Engine plugins’ setting has three options for parsing plugins:

  • None: don’t parse anything in the Plugins folder. This reduces parse time the most
  • Referenced: parse only plugins references by the project, and referenced by default. Depending on how many plugins you have installed that are not used, this still reduces parse time. It is the recommended setting
  • All: parse all plugins; there is no reduction in parse time.
Visual Assist Options dialog, showing the settings to index all, referenced, or no Unreal Engine plugins

Real-World Performance Improvements

The amount of time saved by not parsing unused plugins depends on the complexity of your Unreal Engine solution and the specific machine on which Visual Studio runs, but some real-world measurements are as follows:

Time (minutes and seconds) to fully index an Unreal Engine project, when indexing UE plugins. The percentage annotations are the fraction the Referenced Plugins or No Plugins times are of the time indexing the same project with all plugins.

The absolute values may vary but we expect the relative percentage to be broadly applicable.

Notes

If you open a file from a plugin folder which was not parsed (either not referenced, or the above setting was set to None), then you will see a notification message that the file was not parsed and Visual Assist won’t provide your expected functionality for that file. This is shown only once, and won’t be shown again until Visual Studio restarts.

Avoiding Parsing UE-Generated Files

Saving a very useful change for last — there are many places Visual Assist shows you the symbols and files it’s aware of. The two main windows are Open File In Solution which lists all headers (and other files), and Find Symbol will list every symbol in the database. Unreal Engine, however, generates header files, and these include generated symbols, neither of which are useful in practice when coding on your UE project in Visual Studio.

Voila, a new setting, which means Visual Assist won’t show *.generated.h files, and the Find Symbol dialog is not polluted with generated symbols either. The setting is called ‘Index generated code’ and is off by default. That is, the default is aimed at clean results within Visual Assist, to not index these generated files and store those generated symbols. You can always turn it back on if you want the old behaviour.

Visual Assist Options dialog showing the checkbox to index generated code. By default it is off, which means the results shown within Unreal Engine will be cleaner

Unreal Engine with Visual Assist 2021.1 and 2021.2

The above covers only the first two releases this year, and we have more planned. However, the parsing speed improvements (including our followup for more granular parsing of plugins) and removing generated files and symbols by default should the general ‘quality of life’ using Visual Assist with Unreal Engine. As always, feedback is welcome!

Busy Busy Busy!

Are you busy? I know we are. Our development team has been taking a hard look at what’s going on in the development landscape, and I thought we could share a few things that we’ve got going on behind the scenes:

Visual Studio 2022 Public Preview is Here

Visual Studio 2022 is in public beta, with some exciting changes – they’re moving to 64-bit! The team at Microsoft has been super supportive, and we’ve been working on adding full support as we learn more and more about the changes being made. Much of this work is just making sure we’re ready for the release, but there will be some improvements made along the way. Don’t worry. If you’re not ready to move to VS 2022, we’re not dropping support for 2019, or 2017, 2015, or… (we do support a lot of versions, don’t we?) If you are an early adopter, be sure to opt-in for beta downloads. We’ll be releasing a new version with initial support for VS 2022 in the coming weeks!

Unreal Engine 5 Early Access

The team at Epic has been a great partner and supportive of our development efforts, and granted us an early look at some of the things we might encounter with the update. Again, much of the effort is just making sure everything works for UE5 the same way it does for UE4. While initial support is there, we know there will be more to come. We know our game devs are excited about this update and so are we. Again, be sure to sign up for beta to get the latest updates from our end. 

Windows What?

While most (I mean myself) weren’t expecting a big update from Windows, it looks like it is indeed happening. This won’t have as big of an impact on Visual Assist, as we’re more dependent on the IDE than anything else. However, we’re more excited to see what the future holds for Windows and what the downstream effects will be. If you’re in the know, feel free to comment. Either way, we’ll be supporting any moves made as we are able.

All this to say we’re busy and excited about this year in development news. As things get back to somewhat normal in day-to-day life, it looks like we’ll be making up for lost time from 2020 fairly quickly.

Looking for a New Database?

A last note for Visual Studio users: our sister company InterBase has released a new plugin on the VS extension store, adding support for ADO.NET to an already amazing database. We know everyone’s needs around a database are different and think InterBase is a solid mix of lightweight and full-featured with solid encryption all around. Learn more and give it a try here.

How to Set Up VA

Visual Assist is a coding productivity tool for C++ and C# developers. It extends Visual Studio to make the programming experience better by providing tools for understanding code, checking code, and writing code. Some of its benefits include fast navigation, code inspection and modernization, many refactorings, code correction, Unreal Engine 4 support (for which it is famous), and code assistance. In this article, we will walk through the steps needed to set up Visual Assist and show you a very brief overview of how to use it.

1. Installing Visual Assist

First, visit the Whole Tomato Visual Assist website to download the installer. You can use Visual Assist for free for a month as a trial, or alternatively, you can choose to buy a license from the get-go. Keep in mind that once your free trial is over, you will need to buy the license to keep using it.

On the main page, click the red “Try it for free” button, and on the next page, click “Download Free Trial” to download the installer.  

Before downloading the file, you will need to fill in some required information.

Once you have completed this step, your download will begin.

When you are done downloading the installation file, open it to begin the installation process. Visual Assist supports many versions of Visual Studio, and you can install it for any version you have on your computer.

Once the installation is complete, you can immediately start making use of Visual Assist.

When you run Visual Studio, Visual Assist will show you a tip. You can turn this off, but we recommend you keep it on since it shows helpful information about what you can achieve each time you start.

And that’s it! Visual Assist is installed. 

Visual Assist is very powerful but has a very low UI. That’s great for power users who know it well, but if you’re new to using it, it can be harder to discover all the things it can do. Read on for a short intro about using it with a new application. 

Using Visual Assist

The following few steps show you how to create a new application in Visual C++. If you’re familiar with this, you can skip ahead to where we demonstrate Visual Assist.

When starting Visual Studio, you will be directed to the Welcome page, where you will be able to create new projects from the pop-up window. Click on “Create new project” to move to the next step.    

You can create different types of applications using Visual Studio. In this guide, we will create a Windows C++ application for the purpose of illustration. 

Select Windows Desktop Application (note the C++ label) to start building your app. You can select whichever type of application you are interested in building. Once this is complete and you have successfully configured your project, you will finally be able to make use of Visual Assist. Click on “Create” and watch the magic unfold.  

Note that Visual Assist is low UI to prevent it from getting in your way while making use of Visual Studio. Click on “Extensions” in the toolbar and navigate to “VAssistX,” which will present a list of functionalities that you can explore.

You can also access the Quick Action and Refactoring menu by using the following shortcut (Shift+Alt+Q). For a comprehensive list of keyboard shortcuts, click here.

3. Like Visual Assist?

When your trial comes to an end, you will be prompted to use a license. Select “Buy” to purchase a license or “Register” to use an existing one. 

By now you should be able to set up Visual Assist without any problem and start making use of it alongside Visual Studio. To find out more about Visual Assist and some of its functions, and why everyone from developers in major studios right down to students uses it, click here.

Bartłomiej Filipek Reveals Why He’s a Big Fan of Visual Assist

Bartłomiej Filipek Reveals Why He’s a Big Fan of Visual Assist

Bartlomiej Filipek is a software developer from the Polish city of Cracow. Bartek, as he prefers to be called, started coding when he was 14 years old, after reading “C++ in 24h”, and got his first real programming job in 2007. Bartek broad professional experience includes Native Windows Desktop Apps, OpenGL, Gamedev, BioFeedback games, .NET, large-scale app development, flight planning, and graphics driver coding. As a master’s student he also created lectures about OpenGL and gamedev. Since 2014 he has worked as a C++ software developer for Xara.

Bartek took time to tell us about his experience with Visual Assist, and why he’s a big fan.

When did you start using Visual Assist and how long have you been using it?

It’s hard to recall, but it was very early in my professional career. After using Visual Studio (VS 2003 and 2005) for some time, I knew I needed some more productivity enhancements. Visual Studio 2005or 2008 wasn’t best at that. I searched for solutions and found Visual Assist – which was amazing.

What was it like building software before you had Visual Assist?

Visual Studio was great for development, but it lacked some essential improvements like the refactoring helpers. I wasn’t able to efficiently rename my variables or member functions. And most importantly, the speed of Intellisense was relatively poor on large solutions. Sometimes I had to wait a couple of seconds to get the list of methods for my object.

How does Visual Assist help you create your applications?

First of all, I love many refactoring tools that I get with VA. I can quickly and safely rename my variables, functions, and much more. Another important part is code extraction and the ability to move the code back and forth between a header file or the implementation. Additionally, VA is super fast with even larger projects, and I can quickly get a list of member functions, function signatures, and much more. Recently, I have also been exploring VA Code Inspections which helps with code modernization.

What made Visual Assist stand out from other options?I think it’s at least three elements:

I think it has three elements:

  • Performance (as it’s super fast even for large solutions)
  • Lots of refactoring capabilities 
  • Lots of options to understand and move through code faster

What made you happiest about working with Visual Assist?

I like the overall speed of Virtual Assist, I can quickly jump around my code, see definitions, list member functions and even make notes with Hashtags.

What have you been able to achieve through using Virtual Assist to help create your applications?

I think I can write safer code (thanks to code inspections), avoid code smells (like large functions because I can quickly make them smaller with code extraction tools). And overall, it contributes to better quality and readability of my code.

What are some future plans for your applications?

At Xara – my main job – we plan to make some great enhancements to our powerful document online editor. For my other projects, especially blogs and educational content, I hope to experiment with some latest C++ 20 features and practice good modern C++ techniques.


Thank you, Bartek! You can find the link to Bartek’s blog here

https://www.wholetomato.com/downloads
How To Modernize With Visual Assist Part 2

How To Modernize With Visual Assist Part 2

In the previous article, you read about five popular techniques to improve your projects and apply several Modern C++ patterns. Here’s a list of five more things! We’ll go from the override keyword to nullptr, scoped enums, and more. All techniques are super-easy with Visual Assist!

1. Override

Let’s have a look at the following code with a simple class hierarchy:

using BmpData = std::vector<int>;

class BaseBrush {
public:
virtual ~BaseBrush() = default;

virtual bool Generate() = 0;

virtual BmpData ApplyFilter(const std::string&) { return BmpData{}; }
};

class PBrush : public BaseBrush {
public:
PBrush() = default;

bool Generate() { return true; }

BmpData ApplyFilter(const std::string& filterName) {
std::cout << "applying filter: " << filterName;
return BmpData{};
}

private:
BmpData m_data;
};

When you run VA code inspections, you’ll immediately see that it complains about not using the override keyword on those two virtual methods.

image1

In short, the override keyword allows us to explicitly specify that a given member function overrides a function from a base class. It’s a new keyword available since C++11.

As you might already know, you can go to VA Code Inspection Results and apply the fixes automatically. You’ll get the following code:

class PBrush : public BaseBrush {
public:
PBrush() = default;

bool Generate() override;

BmpData ApplyFilter(const std::string& filterName) override;
private:
BmpData m_data;
};

What are the benefits of using override?

The most significant advantage is that we can now easily catch mismatches between the virtual base function and its override. When you have even a slight difference in the declaration, then the virtual polymorphism will might not work. 

Another critical point is code expressiveness. With override, it’s effortless to read what the function is supposed to do.

And another one is being more modern as this keyword is also available in other languages like C#, Visual Basic, Java, and Delphi.

2. nullptr

When I work with legacy code, my Visual Assist Code Inspection Result is often filled with lots of the following items:

image3

This often happens with code like:

if (pInput == NULL) {
    LOG(Error, "input is null!")
    return;
}

or

pObject->Generate("image.bmp", NULL, NULL, 32);

Why does Visual Assist complain about the code? It’s because NULL is just a define and means only 0, so it doesn’t mean a null pointer, but it means 0. This is also a problem when you have code like:

int func(int param);
int func(float* data);
if you call:
func(NULL);

You could expect that the function with the pointer should be called, but it’s not. That’s why it’s often a guideline in C or early C++ that suggests not making function overrides with pointers and integral types.

The solution? Just use nullptr from C++11.

nullptr is not 0, but it has a distinct type nullptr_t.

Now when you write:

func(nullptr);

you can expect the proper function invocation. The version with func(float* data) will be invoked.

Not to mention that nullptr is a separate keyword in C++, so it stands out from the regular code. Sometimes NULL is displayed in a different color, but sometimes it is not.

Visual Assist makes it super easy to apply the fix, and it’s a very safe change.

3. Convert enum to scoped enum

Another pattern that is enhanced with Modern C++ is a way you can define enums.

It was popular to write the following code:

enum ActionType {
    atNone,
    atProcess,
    atRemove,
    atAdd
};

ActionType action = atNone;
Since C++11 it's better to you can define this type in the following way:
enum class ActionType {
    None,
    Process,
    Remove,
    Add
};

ActionType action = ActionType::None;

What are the benefits of such transformations?

  • They don’t pollute the global namespace. As you may have noticed, it was often necessary to add various prefixes so the names wouldn’t clash. That’s why you see atNone. But in the scoped enum version, we can write None.
  • You get strong typing, and the compiler will warn when you want to convert into some integral value accidentally.
  • You can forward scope enums and thus save some file dependencies.

What’s best about Visual Assist is that it has a separate tool to convert unscoped enums to enum classes, all with proper renames and changes in all places where this particular type was used. Right-click on the type and select “Convert Unscoped Enum to Scoped Enum.”. This opens a preview window where you can see and select which references will be replaced.

image2

Read more in Convert Unscoped Enum to Scoped Enum in the VA documentation.

4. Use more auto

One of the key characteristics of Modern C++ is shorter and more expressive code. You saw one example where we converted from for loops with long names for iterators into a nice and compact range-based for loops.

What’s more, we can also apply shorter syntax to regular variables thanks to automatic type deduction. In C++11, we have a “reused” keyword auto for that.

Have a look:

std::vector<int> vec { 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int>::const_iterator cit = vec.cbegin();

We can now replace it with:

std::vector<int> vec { 1, 2, 3, 4, 5, 6, 7, 8};
auto cit = vec.cbegin();

Previously, template-type deduction worked only for functions, but now it’s enabled for variables. It’s similar to the following code:

template <typename T> func(T cit) {
    // use cit...
}
std::vector<int> vec { 1, 2, 3, 4, 5, 6, 7, 8};
func(vec.cbegin()); // template deduction here!

Following are some other examples:

auto counter = 0;   // deduced int
auto factor = 42.5; // deduces double
auto start = myVector.begin(); // deduces iterator type
auto& ref = counter; // reference to int
auto ptr = &factor;  // a pointer to double
auto myPtr = std::make_unique<int>(42);
auto lam = [](int x) { return x*x; };

Have a look at the last line above. Without auto, it wouldn’t be possible to name a type of a lambda expression as it’s only known to the compiler and generated uniquely.

What do you get by using auto?

  • Much shorter code, especially for types with long names
  • Auto variables must always be initialized, so you cannot write unsafe code in that regard
  • Helps with refactoring when you want to change types
  • Helps with avoiding unwanted conversions

As for other features, you’re also covered by Visual Assist, which can automatically apply auto. In many places, you’ll see the following suggestions:

image5

This often happens in places like

SomeLongClassName* pDowncasted = static_cast<SomeLongClassName*>(pBtrToBase); 
// no need to write SomeLongClassName twice:
auto pDonwcasted = static_cast<SomeLongClassName*>(pBtrToBase);

or

unsigned int val = static_cast<unsigned int>(some_computation / factor);
// just use:
auto val = static_cast<unsigned int>(some_computation / factor);

As you can see, thanks to auto, we get shorter code and, in most cases, more comfortable to read. If you think that auto hides a type name for you, you can hover on it, and the Visual Studio will show you that name. Additionally, things like “go to definition” from Visual Assist work regularly.

5. Deprecated functionality

With C++11, a lot of functionality was marked as deprecated and was removed in C++17. Visual Assist helps with conversion to new types and functions.

For example, it’s now considered unsafe to use random_shuffle as it internally relied on simple rand(), which is very limited as a random function generator.

std::vector<int> vec { 1, 2, 3, 4, 5, 6, 7, 8 };
std::random_shuffle(vec.begin(), vec.end());

Visual Assist can replace the above code with the following:

std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));

Additionally, you’ll get suggestions to improve old C-style headers and convert them into C++ style:

image4

Some other handy fixes

We have covered a few inspections, but there’s much more! Here are some exciting items that you might want to see:

The whole list is available here: List of Code Inspections

Summary

Thanks for reading our small series on Clang Tidy, Code Inspections, and Visual Assist. We covered a lot of items, and I hope you learned something new. The techniques I presented in most cases are very easy to use, especially thanks to VA support, and you can gradually refactor your code into Modern C++.

https://www.wholetomato.com/downloads