Tips and Tricks

Everything you need to know about code inspections

By now you might have heard about Visual Assist’s code inspections—it has been a staple of almost all recent updates and we hosted two webinars discussing it. This article sums it all in an easy to read and convenient way.

What are code inspections?

Code inspections is a feature in Visual Assist that automatically checks source code for issues and code smells, and suggests the appropriate fix. The main benefit of using code inspection is better overall code quality with minimal effort.

Code inspections work by utilizing code checkers, sometimes referred to as static analyzers. These are tools that analyze your source code passively—it happens as you type your code. You do not need to actually compile and execute your code to detect a problem (i.e. finding bugs and errors using run-time techniques such as testing).

Code issues are underlined in blue. Line information and a description of the issue is also shown in the VA Code Inspection Results window.

It looks for common patterns, broken coding conventions, and potential bugs in the code using algorithms and special techniques. The purpose of code checkers is to catch problems early in the development process, which can save a lot of time and effort later on. 

What issues can it detect?

The issues and code smells that can be detected vary widely from stylistic infractions on coding convention, all the way to system critical errors.  Here are some of the common fixable issues:

  • Detecting and updating obsolete coding syntax
  • Highlights possible readability issues and broken coding conventions
  • Checking type-related errors (such as making invalid type conversions or assigning values of incompatible types, using uninitialized variables, or.)
  • Wasted resources due to inefficient memory allocation/deallocation.
  • Other issues of non-obvious, but potentially dangerous, incorrectness

Visual Assist’s code inspection feature is based on LLVM’s /Clang-Tidy code analysis engine so you can be sure that it covers a variety of checks targeted at finding security and API usage bugs, dead code, and other logic errors. Additionally, we extend the functionality through the use of ‘evaluated’ checkers (more below).

READ: More examples from a blog by Bartek from C++ Stories

Evaluated and unevaluated checkers

Code checkers are added gradually to the list of Visual Assist code inspections. All checkers that are in the list are thoroughly evaluated, checked, and tested. Evaluated checkers often include changed functionality that is not in the base clang-tidy, making them more reliable and safe. This is a key part of the value of the checkers we include. Using evaluated checkers guarantees that the code will be refactored properly and any suggested fix will not break anything.

On the other hand, unevaluated checkers are still based on Clang-Tidy’s extensive list but have not undergone the same quality assurance tests as its counterparts. Almost a hundred unevaluated checkers have been added in Visual Assist 2023.2.

Note that unevaluated checkers will still suggest the recommended fix and behave like normal checks, but users are advised to manually ensure that everything is working correctly. The benefit that this brings is that developers can know what and where a potential issue lies—which is oftentimes the bulk of the work.

Why use code inspections to fix issues and refactor code?

Running code inspections lists down issues in a window for you to examine before implementing fixes.

Code inspections read source code line by line, analyzing the structure, logic, and syntax. It pays attention to specific patterns or coding conventions that may indicate potential issues. As they encounter a line of code, it uses a set of rules and algorithms to determine if the code adheres to best practices or if there are any deviations.

Using code inspections automates a lot of the manual checking and verification that developers would traditionally do. With it, it no longer matters how familiar a developer is on a project, or how large a solution is—it all goes under the same level of scrutiny.

it provides some of the following benefits as well:

  • Be able to utilize modern coding practices without actually knowing them.
  • Improve code quality with minimal refactoring risk.
  • Detecting potential code issues early.

WATCH: Understand how code inspections are evaluated

How to use code inspections to eliminate code smells

First, make sure to enable it by navigating to Extensions -> VAssistX -> Code Inspection (beta) -> Enable code inspection. 

Then you can either click on detected issues underlined in blue, use the Quick Refactoring Menu (Shift + Alt + Q) while on the highlighted issue, or use the code inspection dialogue to implement changes in batches.

WATCH: Code inspections in action

Visual Assist by Whole Tomato: Filling Gaps in Visual Studio for C/C++ and C# Developers

Visual Assist is a productivity extension for Visual Studio development work. It provides a set of intelligent refactoring, navigation, code highlighting and generation features for C, C++, and C# development. With its highly-efficient memory management and minimal UI, Visual Assist gives developers uninterrupted access to advanced features without slowing down the IDE.

Visual Assist is one of the definitive plugins that conceptualized and shaped most of the current features you see now in Visual Studio. And to this day it continues to develop user-centric design for maximum productivity and usability.

Frequently Asked Questions About Code Inspection in Programming

What is code inspection in programming?

Code inspection is a static analysis process that scans source code for bugs, errors, and code smells without executing it. It works using automated tools that analyze code as you write. This helps developers catch issues early and maintain high code quality. It also reduces the need for heavy debugging later.

How is code inspection different from code review?

Code inspection is automated and focuses on detecting technical issues like errors and bad practices instantly. Code review, on the other hand, is a manual process where developers evaluate logic, structure, and readability. Both are important but serve different purposes. Together, they create a more reliable development workflow.

What types of issues can code inspection detect?

Code inspection tools can identify syntax errors, unused variables, memory issues, and incorrect type usage. They also highlight code smells like poor readability and inefficient logic. Some tools even detect potential security risks and dead code. This wide coverage helps improve both performance and maintainability.

Why should developers use code inspection tools?

Code inspection tools help developers catch problems early in the development process. They reduce manual effort, enforce coding standards, and improve overall code quality. By identifying issues instantly, they save time and prevent costly fixes later. This makes development faster and more efficient.

Does code inspection find all bugs in the code?

Code inspection cannot detect all types of bugs, especially those related to runtime behavior or complex logic. It mainly focuses on static issues that can be identified without executing the code. Developers still need testing and debugging for complete validation. However, it significantly reduces common errors early on.

What is static code analysis and how is it related to code inspection?

Static code analysis is the process of analyzing code without running it to find issues. Code inspection is a type of static analysis that provides real-time feedback as you write code. It uses predefined rules and patterns to detect problems. This makes it an essential part of modern development practices.

How do I enable code inspections in Visual Assist?

To enable code inspections, go to Extensions ? VAssistX ? Code Inspection and turn the feature on. Once enabled, issues will appear highlighted directly in your code editor. You can click on them to view details and apply fixes. This allows quick and efficient code improvement.

What is the difference between evaluated and unevaluated checkers?

Evaluated checkers are tested and optimized to ensure safe and reliable code fixes. Unevaluated checkers offer a wider range of issue detection but may not be fully tested. Developers should review their suggestions carefully before applying changes. Using both can balance safety and coverage.

Do code inspection tools affect IDE performance?

Most modern code inspection tools are designed to run efficiently with minimal impact on performance. However, enabling too many rules or working on large projects can slightly slow down the IDE. Adjusting settings and limiting active checkers can help maintain speed. Overall, the benefits usually outweigh the performance cost.

Download Visual Assist here.

Related posts
NewsTips and Tricks

Visual Assist’s AI Assistant: Things You Can Do with VA Intelligence Right Now

Tips and Tricks

Blueprints Aren’t Always A Choice: How Your IDE Shapes The Way You Learn Unreal Engine Development

CommunityNews

Meet Whole Tomato’s new AI Assistant: Instant Answers for Visual Assist Users

Success Story

User Case Study: From AAA to Indie—How She Was Such A Good Horse Studio built Into the Unwell

Leave a Reply

%d