{"id":1842,"date":"2021-03-11T18:45:22","date_gmt":"2021-03-11T22:45:22","guid":{"rendered":"https:\/\/blog.wholetomato.com\/?p=1842"},"modified":"2024-04-11T14:04:41","modified_gmt":"2024-04-11T18:04:41","slug":"how-to-modernize-c-code-with-visual-assist-in-five-easy-steps","status":"publish","type":"post","link":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/","title":{"rendered":"How to Modernize C++ Code with Visual Assist in Five Easy Steps"},"content":{"rendered":"\r\n<p>You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we&#8217;ll take a look at some techniques you might apply to get nicer code and be closer to the best feature that recent versions of C++ offer.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Let&#8217;s start!\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>1. Rename and Aim for Meaningful Names<\/strong> You might be surprised by the first point on our list.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Is rename added to C++11 as a feature?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>No, it\u2019s definitely not just an element of C++. In fact, having good names is not a feature of any programming language, as it depends on your style. The compiler can take any names, including single letters and even almost any Unicode character. Thanks to better IDE support and powerful text editors, we can now avoid shortcuts and rely on full and meaningful names.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>And what&#8217;s most important is that we can leverage extra refactoring tools, like those from Visual Assist, to fix code with the legacy style.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Let&#8217;s have a look at the following class:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">class PBrush { \r\npublic: \r\n\tPBrush(); \r\n\t~PBrush(); \r\n\r\n\tbool Gen(HDC r) { } \r\n\tbool IsAval() const { return aval; } \r\n\r\nprivate: \r\n\tbool aval; \r\n\t\r\n\tHGLOBAL m_hGlobal; \r\n\tLPBITMAPINFO lpBitmap; \r\n\tLPBYTE lpBits; \r\n\tHDC ReferenceDC; \r\n\t\r\n\tRGBQUAD m_pal[256]; \r\n}; <\/pre>\r\n\r\n\r\n\r\n<p>Read the above code and think about potential naming issues. Is the code clear and descriptive? What would you change?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Or take a look at the following function, which uses this <strong>PBrush<\/strong> objects:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;PBrush*&gt; FilterAvalBrushes(const std::vector&lt;PBrush*&gt;&amp; brs) { std::vector&lt;PBrush*&gt; o;\r\n\tULONG totalBCount = 0; \r\n\tsize_t totalBitmaps = 0; \r\n\t\r\n\tfor (size_t i = 0; i &lt; brs.size(); ++i) { \r\n\t\tif (brs[i]-&gt;IsAval()) { \r\n\t\t\to.push_back(brs[i]); \r\n\t\t\t++totalBitmaps; \r\n\t\t\ttotalBCount += brs[i]-&gt;GetByteCount(); \r\n\t\t} \r\n\t} \r\n\t\r\n\t\/\/ make sure they have some bits ready: \r\n\tfor (size_t i = 0; i &lt; o.size(); ++i) { \r\n\t\tif (!o[i]-&gt;Bits()) \r\n\t\t\tLog(\"ERROR, empty bitmap!\"); \r\n\t} \r\n\t\r\n\tLog(\"Byte count %d, total bitmaps %d\", totalBCount, totalBitmaps); return o; \r\n}<\/pre>\r\n\r\n\r\n\r\n<p>How could we improve the code?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>You might be tempted to say that it&#8217;s better to leave old code and not touch it since other systems might depend on it. However, adding or changing to better names and keeping it useful to other systems is very simple. In most cases, you can find and replace old names or use Rename from Visual Assist.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Visual Assist has a powerful feature for renaming objects and making sure the code compiles after this transformation. It was also one of the earliest VA features and enabled using this refactoring capability years before Visual Studio added it.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>You can invoke the rename tool in many situations.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>The simplest way is to hit a key shortcut when your cursor is inside a particular name ( <strong>Shift + Alt + R<\/strong> by default). For example, let&#8217;s say that I&#8217;d like to rename <strong>bool aval<\/strong>, so I move my cursor there and invoke the dialog, and then I can see the following window:\u00a0<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"893\" height=\"396\" data-attachment-id=\"1852\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/rename_dialog\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?fit=893%2C396&amp;ssl=1\" data-orig-size=\"893,396\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"rename_dialog\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?fit=300%2C133&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?fit=893%2C396&amp;ssl=1\" class=\"wp-image-1852\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?resize=893%2C396&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?w=893&amp;ssl=1 893w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?resize=300%2C133&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?resize=768%2C341&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/rename_dialog.png?resize=360%2C160&amp;ssl=1 360w\" sizes=\"auto, (max-width: 893px) 100vw, 893px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>Another option is to write a new name, and then VA will show a handy context menu where you can invoke the rename or see the preview window before making the changes.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>What other things can you do with rename?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Improve consistency of names. For example, your style guide might suggest adding <strong>m_<\/strong> before each nonstatic data member for classes. So you might quickly improve it and add this prefix for classes that don&#8217;t share this style. In our example, some names start with <strong>m_<\/strong> while others don&#8217;t.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>It&#8217;s not only variables and functions but also things like enumerations and namespaces.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>But most importantly, what name would be better for <strong>aval<\/strong>? Do you prefer <strong>m_isAvailable<\/strong> ? or Available ? I&#8217;ll leave it as an exercise.\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>2. Extract Smaller Functions<\/strong><strong>\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Here&#8217;s another example to fix:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/ number of data components \r\nswitch ( format ) \r\n{ \r\ncase GL_RGB: \r\ncase GL_BGR_EXT: components = 3; break; \r\ncase GL_RGBA: \r\ncase GL_BGRA_EXT: components = 4; break; \r\ncase GL_LUMINANCE: components = 1; break; \r\ndefault: components = 1; \r\n} \r\n\r\nGLuint t; \r\nglGenTextures(1, &amp;t); \r\n\r\n\/\/ load data \r\nHBITMAP hBmp = (HBITMAP)LoadImage(NULL, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); \r\nif (hBmp == NULL) \r\n\treturn 0; \r\n\t\r\n\/\/ rest of code... long code<\/pre>\r\n\r\n\r\n\r\n<p>The above code is just a part of some longer function that loads, opens a file, loads bytes, and creates an OpenGL texture object with the loaded data. One thing that we might immediately do is to make this function smaller. More compact functions are easier to read and allow for more code reuse.\u00a0 We can see that it has several smaller subtasks, so it would be better to extract them into separate parts. For example, we can implement <strong>FormatToComponents<\/strong>:\u00a0<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"368\" data-attachment-id=\"1853\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/extract_method\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?fit=785%2C368&amp;ssl=1\" data-orig-size=\"785,368\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"extract_method\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?fit=300%2C141&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?fit=785%2C368&amp;ssl=1\" class=\"wp-image-1853\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?resize=785%2C368&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?w=785&amp;ssl=1 785w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?resize=768%2C360&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method.png?resize=360%2C169&amp;ssl=1 360w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>And when you select this context menu, you&#8217;ll get the following dialog:\u00a0<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"506\" height=\"275\" data-attachment-id=\"1854\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/extract_method_ui\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?fit=506%2C275&amp;ssl=1\" data-orig-size=\"506,275\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"extract_method_ui\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?fit=300%2C163&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?fit=506%2C275&amp;ssl=1\" class=\"wp-image-1854\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?resize=506%2C275&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?w=506&amp;ssl=1 506w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?resize=300%2C163&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/extract_method_ui.png?resize=360%2C196&amp;ssl=1 360w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>After some adjustments (for example, we don&#8217;t need to take components as input argument), we can prepare the following code:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">int FormatToComponents(GLenum format) { \r\n\tswitch (format) { \r\n\tcase GL_RGB: \r\n\tcase GL_BGR_EXT: return 3; \r\n\tcase GL_RGBA: \r\n\tcase GL_BGRA_EXT: return 4; \r\n\tcase GL_LUMINANCE: return 1; \r\n\t} \r\n\treturn 1; \r\n} <\/pre>\r\n\r\n\r\n\r\n<p>And then call it from our initial function:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">GLuint LoadTextureFromBmp(const char *fname, GLenum format, GLuint filter) { const int components \r\n\t= FormatToComponents(format);  <\/pre>\r\n\r\n\r\n\r\n<p>This not only gave us shorter, cleaner code, but also we can now mark our variable as const, which even improves the quality. Additionally, this function might be reused in some other places of the system.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Here are the general rules for the extraction by VA:\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Symbols available globally, or within the class of the original and new methods, are not passed via a parameter list.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Symbols used only in the right side of expressions (i.e., not modified) are passed by value. Symbols used in the left side of expressions (i.e., assigned) are passed by reference. Symbols referenced with dot notation within the extracted code (e.g., classes and structs) are always passed by reference.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>When a newly created method assigns a value to only one symbol, that symbol is passed by value and the assignment is done in the original method via return value.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Symbols local to extracted code become local to the new method; they are not passed.<\/p>\r\n\r\n\r\n\r\n<p>\u00a0<strong>3. Improve Function Interfaces<\/strong><strong>\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Let&#8217;s now challenge ourselves with this one:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">bool Init2d(HDC hdcContext, FontMode fm, HFONT hFont, GLuint iWidth, GLuint iHeigth, GLuint iTexture, bool forceBold, bool forceItalic, size_t numGlyphs); <\/pre>\r\n\r\n\r\n\r\n<p>It&#8217;s a member function in GLFont that is responsible for creating a texture font from a Window font. We can later use this created object to draw text in an OpenGL application.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Isn&#8217;t it worrying that this function takes nine input arguments?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>And here&#8217;s an even more suspicious-looking call site:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">glFont.Init2d(const_cast&lt;CGLApp *&gt;(glApp)-&gt;GetHdc(), fmBitmap, hFont, iWidth, iHeight, 0, false, false, 256);<\/pre>\r\n\r\n\r\n\r\n<p>Some books suggest that if you have more than 5&#8230; or 7, then it&#8217;s some worrying code smell.\u00a0 Such long lists of function arguments are hard to read, and caller sites might easily put them in a wrong order. Another issue is that there are a few boolean parameters, and it&#8217;s hard to see what they mean from the caller perspective.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>You can use Change Signature to modify all parts of a signature, including:\u00a0<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Method name\u00a0<\/li>\r\n<li>Return type\u00a0<\/li>\r\n<li>Visibility\u00a0<\/li>\r\n<li>Parameter names\u00a0<\/li>\r\n<li>Parameter types\u00a0<\/li>\r\n<li>Parameter order\u00a0<\/li>\r\n<li>Number of parameters\u00a0<\/li>\r\n<li>Qualifiers\u00a0<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>The plan for our function is to introduce a structure that would hold all parameters. We can do it by simply copying the parameter list and putting it into a structure above the function declaration:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">struct FontCreationParams { \r\n\tGLuint iWidth; \r\n\tGLuint iHeigth; \r\n\tGLuint iTexture { 0 }; \r\n\tbool forceBold { false}; \r\n\tbool forceItalic { false}; \r\n\tsize_t numGlyphs { 256 }; \r\n}; <\/pre>\r\n\r\n\r\n\r\n<p>As you can see, I even assigned some default values.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>And then we can change the signature in two steps:\u00a0<\/p>\r\n\r\n\r\n\r\n<p>1. Add new argument to the function: const FontCreationParams&amp; param with a default value of TODO.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>2. And then, again remove those extra arguments.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Then you might compile code and fix call sites.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>The final code might look as follows:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">FontCreationParams params; \r\nparams.iWidth = iWidth; \r\nparams.iHeigth = iHeight; \r\nglFont.Init2d(const_cast&lt;CGLApp *&gt;(glApp)-&gt;GetHdc(), fmBitmap, hFont, params);<\/pre>\r\n\r\n\r\n\r\n<p>With this approach, if you need some more parameters (or you need to alter them), it&#8217;s just a matter of modifying the structure, and the function declaration will be the same.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>While you can do such a change manually, Visual Assist makes it much more comfortable and takes care of most of the cases at the call site. So this significantly simplifies and automates the process when you have many function calls.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>So far, we discussed basic principles for code modernization, but how about automation? Can we use extra tools that would tell us what to change in our code?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Let&#8217;s see the fourth point.\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>4. Enable Code Inspections<\/strong><strong>\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Since a few years ago, Visual Assist has come with code Inspections that automatically check your code and pinpoint any issues.\u00a0<\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>Code Inspection analyzes C\/C++ for specific code quality issues as you edit. The feature, based on LLVM\/Clang, warns you of issues in your code and if possible, suggests and applies quick fixes.\u00a0<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>You can enable them via Settings or as shown below:\u00a0<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"985\" height=\"714\" data-attachment-id=\"1855\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/enable_code_inspections\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?fit=985%2C714&amp;ssl=1\" data-orig-size=\"985,714\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"enable_code_inspections\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?fit=300%2C217&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?fit=985%2C714&amp;ssl=1\" class=\"wp-image-1855\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?resize=985%2C714&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?w=985&amp;ssl=1 985w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?resize=300%2C217&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?resize=768%2C557&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enable_code_inspections.png?resize=360%2C261&amp;ssl=1 360w\" sizes=\"auto, (max-width: 985px) 100vw, 985px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>You can read the full description of Inspections in the excellent documentation website Introduction to Code Inspection and also see our previous article where we dive a bit deeper A Brief Introduction to Clang-Tidy and Its Role in Visual Assist \u2013 Tomato Soup.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Currently,\u00a0 we have almost 30 code inspections, and the number grows with each revision: List of Code Inspections.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>They range from checking <strong>.empty()<\/strong> vs <strong>size()<\/strong> , using <strong>emplace_back()<\/strong>, <strong>nullptr<\/strong> usages, and many more. They can help not only with code modernization but even with finding some performance issues in code. It&#8217;s like a small code analysis run on the code.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Let\u2019s\u00a0 take a look at one related to for loops.\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>5. Make For-Loops More Compact<\/strong><strong>\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>One of the coolest elements of C++11 style comes from using simpler for loops. This is especially important for code that uses containers from the Standard Library.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>For example, before C++11, you had to write:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector { }... \r\nfor (std::vector&lt;int&gt;::iterator it = vec.begin(); it != vec.end(); ++it) std::cout &lt;&lt; *it &lt;&lt; '\\n'; <\/pre>\r\n\r\n\r\n\r\n<p>Now, this can be simplified with this simple syntax:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;int&gt; vec { 1, 2, 3, 4, 5, 6 }; \r\nfor (const auto&amp; elem : vec) \r\n\tstd::cout &lt;&lt; elem &lt;&lt; '\\n';<\/pre>\r\n\r\n\r\n\r\n<p>Why not automate this transformation?\u00a0<\/p>\r\n\r\n\r\n\r\n<p>VA identifies places where you can use this modern syntax and then rewrites loops for you.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Consider this example:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;PBrush*&gt; FilterAvalBrushes(const std::vector&lt;PBrush*&gt;&amp; brushes) { \/\/ ... \r\n\tfor (size_t i = 0; i &lt; brushes.size(); ++i) { \r\n\t\tif (brushes[i]-&gt;IsAval()) { \r\n\t\t\tout.push_back(brushes[i]); \r\n\t\t\t++totalBitmaps; \r\n\t\t} \r\n\t} \r\n} <\/pre>\r\n\r\n\r\n\r\n<p>When code inspections are enabled, we can see the following suggestions:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"397\" data-attachment-id=\"1857\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/for_loop_convert\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?fit=819%2C397&amp;ssl=1\" data-orig-size=\"819,397\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"for_loop_convert\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?fit=300%2C145&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?fit=819%2C397&amp;ssl=1\" class=\"wp-image-1857\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?resize=819%2C397&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?w=819&amp;ssl=1 819w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?resize=300%2C145&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?resize=768%2C372&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/for_loop_convert.png?resize=360%2C175&amp;ssl=1 360w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>What&#8217;s nice about Visual Assist is that it&#8217;s very smart and tries to deduce the correct loop syntax.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>For example, when our vector holds pointers, then the converted loop is as follows:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;PBrush*&gt; FilterAvalBrushes(const std::vector&lt;PBrush*&gt;&amp; brushes) { \/\/ ... \r\n\tfor (auto brushe : brushes) { \r\n\t\tif (brushe-&gt;IsAval()) { \r\n\t\t\tout.push_back(brushe); \r\n\t\t\t++totalBitmaps; \r\n\t\t\ttotalBCount += brushe-&gt;GetByteCount(); \r\n\t\t} \r\n\t} \r\n} <\/pre>\r\n\r\n\r\n\r\n<p>But when we change the type into <strong>const std::vector&lt;PBrush&gt;<\/strong> (so it holds not pointer but &#8220;full&#8221; objects), then the loop is as follows:\u00a0<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-syntaxhighlighter-code\">for (const auto &amp; brushe : brushes) { \r\n\tif (brushe.IsAval()) { \r\n\t\tout.push_back(brushe); \r\n\t\t++totalBitmaps; \r\n\t\ttotalBCount += brushe.GetByteCount(); \r\n\t} \r\n}<\/pre>\r\n\r\n\r\n\r\n<p>The system is smart and avoids situations where you&#8217;d copy objects during loop iteration, as it&#8217;s more efficient to use references.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>That&#8217;s just a taste of what you can automatically do with Visual Assist and its code inspections!\u00a0<\/p>\r\n\r\n\r\n\r\n<p><strong>Summary<\/strong><strong>\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>In this article, you&#8217;ve seen five suggestions on how to check and improve your code. We started with something fundamental but often skipped: naming. Then we made functions smaller and with better interfaces. And at the end, we enabled code inspections so that Visual Assist can automatically identify more things to repair.\u00a0<\/p>\r\n\r\n\r\n\r\n<p>In the last item, we looked at loop transformation, which is available from C++11. Thanks to Visual Assist, we can automate this task and quickly modernize our code to the newer standard\u00a0<\/p>\r\n\r\n\r\n\r\n<p>After such refactoring, we aim to have safer, more readable code. What\u2019s more, with more expressive code, we can help the compiler to identify potential errors. This is just a start, and stay tuned for the next article where you&#8217;ll see other code modernization techniques: <strong>override<\/strong> keyword, <strong>nullptr<\/strong>, <strong>enum class<\/strong>, <strong>auto<\/strong> type deduction, and deprecated headers.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.wholetomato.com\/\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"200\" data-attachment-id=\"1811\" data-permalink=\"https:\/\/www.wholetomato.com\/blog\/007_banner_wholetomato_resize_emiliano_600x200\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=600%2C200&amp;ssl=1\" data-orig-size=\"600,200\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"007_banner_wholetomato_resize_emiliano_600x200\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=300%2C100&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=600%2C200&amp;ssl=1\" class=\"wp-image-1811\" src=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=600%2C200&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?w=600&amp;ssl=1 600w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=300%2C100&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=360%2C120&amp;ssl=1 360w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern&#8230;<\/p>\n","protected":false},"author":183830964,"featured_media":1858,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[672],"tags":[910314,2426,54971,4458826,621688,885520,78684782,318578,1788,12004844],"class_list":["post-1842","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","tag-analyze","tag-c","tag-c11","tag-code-inspection","tag-extract","tag-for-loop","tag-modern-c","tag-rename","tag-tips","tag-visual-assist"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enablecodedevice.jpg?fit=1920%2C1080&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfpLS4-tI","aioseo_head":"\n\t\t<!-- All in One SEO Pro 4.9.7.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we&#039;ll take a look at some techniques you might apply to get\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Bartlomiej Filipek\"\/>\n\t<meta name=\"google-site-verification\" content=\"DtHrwoEjg0KG_fbuPSp5j_wNIf-g5hSh4EH6tZBoCIw\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO Pro (AIOSEO) 4.9.7.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Tomato Soup - Visual Assist Team Blog\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup\" \/>\n\t\t<meta property=\"og:description\" content=\"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we&#039;ll take a look at some techniques you might apply to get\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2021-03-11T22:45:22+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2024-04-11T18:04:41+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wholetomatosoftware\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@visualassist\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup\" \/>\n\t\t<meta name=\"twitter:description\" content=\"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we&#039;ll take a look at some techniques you might apply to get\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@visualassist\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#blogposting\",\"name\":\"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup\",\"headline\":\"How to Modernize C++ Code with Visual Assist in Five Easy Steps\",\"author\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/author\\\/bartlomiejfilipek6eba5efda2\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.wholetomato.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/enablecodedevice.jpg?fit=1920%2C1080&ssl=1\",\"width\":1920,\"height\":1080},\"datePublished\":\"2021-03-11T18:45:22-04:00\",\"dateModified\":\"2024-04-11T14:04:41-04:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#webpage\"},\"articleSection\":\"Tips and Tricks, analyze, c++, c++11, code inspection, extract, for loop, modern c++, rename, tips, visual assist, English\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/category\\\/tips-and-tricks\\\/#listItem\",\"name\":\"Tips and Tricks\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/category\\\/tips-and-tricks\\\/#listItem\",\"position\":2,\"name\":\"Tips and Tricks\",\"item\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/category\\\/tips-and-tricks\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#listItem\",\"name\":\"How to Modernize C++ Code with Visual Assist in Five Easy Steps\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#listItem\",\"position\":3,\"name\":\"How to Modernize C++ Code with Visual Assist in Five Easy Steps\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/category\\\/tips-and-tricks\\\/#listItem\",\"name\":\"Tips and Tricks\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/#organization\",\"name\":\"Tomato Soup\",\"description\":\"Visual Assist Team Blog\",\"url\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/\",\"email\":\"info@wholetomato.com\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":0,\"maxValue\":100},\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.wholetomato.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/WT_symbol.png?fit=112%2C112&ssl=1\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#organizationLogo\",\"width\":112,\"height\":112,\"caption\":\"visual assist main tomato symbol icon\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#organizationLogo\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/wholetomatosoftware\",\"https:\\\/\\\/twitter.com\\\/visualassist\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/Wholetomatosoftware\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/whole-tomato-software\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/author\\\/bartlomiejfilipek6eba5efda2\\\/#author\",\"url\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/author\\\/bartlomiejfilipek6eba5efda2\\\/\",\"name\":\"Bartlomiej Filipek\",\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5f475f9df35255c22f22f08dbc22d89b5cd931d51ea70e775bb206c45f930bca?s=96&d=blank\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#webpage\",\"url\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/\",\"name\":\"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup\",\"description\":\"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we'll take a look at some techniques you might apply to get\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/author\\\/bartlomiejfilipek6eba5efda2\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/author\\\/bartlomiejfilipek6eba5efda2\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.wholetomato.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/enablecodedevice.jpg?fit=1920%2C1080&ssl=1\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#mainImage\",\"width\":1920,\"height\":1080},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\\\/#mainImage\"},\"datePublished\":\"2021-03-11T18:45:22-04:00\",\"dateModified\":\"2024-04-11T14:04:41-04:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/\",\"name\":\"Tomato Soup\",\"description\":\"Visual Assist Team Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.wholetomato.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO Pro -->\r\n\t\t<title>How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup<\/title>\n\n","aioseo_head_json":{"title":"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup","description":"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we'll take a look at some techniques you might apply to get","canonical_url":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"google-site-verification":"DtHrwoEjg0KG_fbuPSp5j_wNIf-g5hSh4EH6tZBoCIw","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#blogposting","name":"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup","headline":"How to Modernize C++ Code with Visual Assist in Five Easy Steps","author":{"@id":"https:\/\/www.wholetomato.com\/blog\/author\/bartlomiejfilipek6eba5efda2\/#author"},"publisher":{"@id":"https:\/\/www.wholetomato.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enablecodedevice.jpg?fit=1920%2C1080&ssl=1","width":1920,"height":1080},"datePublished":"2021-03-11T18:45:22-04:00","dateModified":"2024-04-11T14:04:41-04:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#webpage"},"isPartOf":{"@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#webpage"},"articleSection":"Tips and Tricks, analyze, c++, c++11, code inspection, extract, for loop, modern c++, rename, tips, visual assist, English"},{"@type":"BreadcrumbList","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.wholetomato.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/#listItem","name":"Tips and Tricks"}},{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/#listItem","position":2,"name":"Tips and Tricks","item":"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#listItem","name":"How to Modernize C++ Code with Visual Assist in Five Easy Steps"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#listItem","position":3,"name":"How to Modernize C++ Code with Visual Assist in Five Easy Steps","previousItem":{"@type":"ListItem","@id":"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/#listItem","name":"Tips and Tricks"}}]},{"@type":"Organization","@id":"https:\/\/www.wholetomato.com\/blog\/#organization","name":"Tomato Soup","description":"Visual Assist Team Blog","url":"https:\/\/www.wholetomato.com\/blog\/","email":"info@wholetomato.com","numberOfEmployees":{"@type":"QuantitativeValue","minValue":0,"maxValue":100},"logo":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2026\/05\/WT_symbol.png?fit=112%2C112&ssl=1","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#organizationLogo","width":112,"height":112,"caption":"visual assist main tomato symbol icon"},"image":{"@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#organizationLogo"},"sameAs":["https:\/\/www.facebook.com\/wholetomatosoftware","https:\/\/twitter.com\/visualassist","https:\/\/www.youtube.com\/c\/Wholetomatosoftware","https:\/\/www.linkedin.com\/company\/whole-tomato-software"]},{"@type":"Person","@id":"https:\/\/www.wholetomato.com\/blog\/author\/bartlomiejfilipek6eba5efda2\/#author","url":"https:\/\/www.wholetomato.com\/blog\/author\/bartlomiejfilipek6eba5efda2\/","name":"Bartlomiej Filipek","image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/5f475f9df35255c22f22f08dbc22d89b5cd931d51ea70e775bb206c45f930bca?s=96&d=blank"}},{"@type":"WebPage","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#webpage","url":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/","name":"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup","description":"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we'll take a look at some techniques you might apply to get","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.wholetomato.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#breadcrumblist"},"author":{"@id":"https:\/\/www.wholetomato.com\/blog\/author\/bartlomiejfilipek6eba5efda2\/#author"},"creator":{"@id":"https:\/\/www.wholetomato.com\/blog\/author\/bartlomiejfilipek6eba5efda2\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/enablecodedevice.jpg?fit=1920%2C1080&ssl=1","@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#mainImage","width":1920,"height":1080},"primaryImageOfPage":{"@id":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/#mainImage"},"datePublished":"2021-03-11T18:45:22-04:00","dateModified":"2024-04-11T14:04:41-04:00"},{"@type":"WebSite","@id":"https:\/\/www.wholetomato.com\/blog\/#website","url":"https:\/\/www.wholetomato.com\/blog\/","name":"Tomato Soup","description":"Visual Assist Team Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.wholetomato.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Tomato Soup - Visual Assist Team Blog","og:type":"article","og:title":"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup","og:description":"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we'll take a look at some techniques you might apply to get","og:url":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/","article:published_time":"2021-03-11T22:45:22+00:00","article:modified_time":"2024-04-11T18:04:41+00:00","article:publisher":"https:\/\/www.facebook.com\/wholetomatosoftware","twitter:card":"summary_large_image","twitter:site":"@visualassist","twitter:title":"How to Modernize C++ Code with Visual Assist in Five Easy Steps - Tomato Soup","twitter:description":"You probably know that over time our projects seem to get old and legacy. Code written now might look suspicious five years later. With the standardization of C++11 in 2011, developers coined the term Modern C++. In this article (and the next one) we'll take a look at some techniques you might apply to get","twitter:creator":"@visualassist"},"aioseo_meta_data":{"post_id":"1842","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"open_ai":"{\"title\":{\"suggestions\":[],\"usage\":0},\"description\":{\"suggestions\":[],\"usage\":0}}","ai":null,"created":"2022-02-02 22:51:09","updated":"2025-05-29 19:50:14","reviewed_by":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t<a href=\"https:\/\/www.wholetomato.com\/blog\" title=\"Home\">Home<\/a>\n<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t<a href=\"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/\" title=\"Tips and Tricks\">Tips and Tricks<\/a>\n<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\tHow to Modernize C++ Code with Visual Assist in Five Easy Steps\n<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.wholetomato.com\/blog"},{"label":"Tips and Tricks","link":"https:\/\/www.wholetomato.com\/blog\/category\/tips-and-tricks\/"},{"label":"How to Modernize C++ Code with Visual Assist in Five Easy Steps","link":"https:\/\/www.wholetomato.com\/blog\/how-to-modernize-c-code-with-visual-assist-in-five-easy-steps\/"}],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/users\/183830964"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/comments?post=1842"}],"version-history":[{"count":20,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1842\/revisions"}],"predecessor-version":[{"id":3599,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1842\/revisions\/3599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/media\/1858"}],"wp:attachment":[{"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/media?parent=1842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/categories?post=1842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wholetomato.com\/blog\/wp-json\/wp\/v2\/tags?post=1842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}