Coding

How to Improve Code Quality with Visual Studio 2013

VisualStudio2013

In this post I will cover how to become a better developer by improving code quality using Visual Studio 2013 features. Code quality covers aspects like correctness, performance, maintainability and elegance. Lets look into few tools and features in Visual Studio 2013 to develop and sustain high standards of code excellence.

1. Code Metrics

It quickly highlights code quality and identifies target for re-factoring thereby improves maintainability. Code metrics can help developers understand which type or methods should be refactored. You can generate code metrics results for an entire solution or a selected project. Code Metrics results are based on the following factors.

  • Maintainability Index – A value between 0 and 100. Higher value is better.
  • Cyclomatic Complexity – A lower number is better.
  • Depth of Inheritance – A lower number is better.
  • Class Coupling – A lower number is better. High coupling indicates a design is difficult to reuse and maintain.
  • Lines of Code – A lower number is better. This count is based on the IL code and not the actual lines of source code.

You can read more about each one of them here https://msdn.microsoft.com/en-us/library/bb385914.aspx

code-metrics-visual-studio-2013

2. CodeLens

CodeLens is included in Visual Studio Ultimate and it helps you to know more about your code without leaving the editor. You can find code references, changes to your code, linked bugs, work items, code reviews, and unit tests.

codelens-visual-studio-2013

You can read more about CodeLens here https://msdn.microsoft.com/en-us/library/hh704261.aspx

You can also install an extension to CodeLens (using Tools -Extensions and Updates) which will also display a Code Health Indicator via CodeLens. The method maintainability numbers will change in real time as you type. This saves time as you do not have to run the analysis all the time to check the code metrics.

codelens-visual-studio-extension

3. Static Code Analysis

Code Analysis is used to analyze managed assemblies and report any programming or design rule violations. These rules are based on Microsoft .NET Framework Design Guidelines. This helps in proactive discovery of potential issues. It also encourages best practices and supports automation like build process. It will make you a better developer. In Visual Studio 2013 it has moved into its own tab from the Error List Window in previous Visual Studio versions. You can run static code analysis on the entire solution or a specific project.

static-code-analysis-visual-studio-2013

4. Code Clone Analysis

This feature in included in Visual Studio Ultimate or Visual Studio Premium. This is to find potentially copied code and refactor them to improve code maintainability. This ensure we are not introducing any bugs that were part of the code that was copied from somewhere. Clones are found even if there are modest changes in the code. This is a customizable feature which can be done by modifying a settings file. You can use code clone analysis when you are fixing a bug, changes to requirements, architectural cleanup or when you have written new code.

code-clone-analysis-visual-studio

You can read more about Code Clone Analysis here https://msdn.microsoft.com/en-us/library/hh205279.aspx

5. Code Review

Code Review feature is only available in Visual Studio Ultimate and Premium versions. Before you check in your code you can request for a peer review. This feature in seamlessly integrated into the IDE to request code reviews, supports commenting on specific code, and is backed by TFS. This leads into a secondary feature Suspend & Resume. It behind the scenes checks your code in to a private branch or shelf.

code-review-visual-studio-2013

6. Powerpoint Storyboarding

With storyboarding you can now turn your ideas or customer requirements into visual mockups by using shapes, text, animation and other features that PowerPoint Storyboarding provides. It also supports mobile storyboarding and also has excellent TFS Work Item Integration.

powerpoint-storyboarding

7. Team Rooms Extension

This helps to access TFS online team rooms feature from within Visual Studio. You also get a historic view of the data.

team-rooms-extension-visual-studio-2013

Apart from all the TFS team room features it also the following features:

  • Multiple chat rooms and support for multiple monitors
  • Toaster Popup in system tray when users join a room
  • Toaster Popup on mention
  • Lync like user search & status tracking
  • Hashtags to track Trending conversations
  • Preference to turn off popup notifications
  • Email users
  • Export Extension Settings

You can download the extension from here https://visualstudiogallery.msdn.microsoft.com/c1bf5e4f-5436-465d-87da-09b2f15ff061

To compare features available in the different versions of visual Studio 2013 please refer this link http://www.visualstudio.com/en-us/products/compare-visual-studio-products-vs.aspx

If you like our content, please consider sharing, leaving a comment or subscribing to our RSS feed to have future posts delivered to your feed reader.

Please follow us on twitter @CodeRewind and like us on facebook

You Might Also Like