Chapter 8

Code Snippets and Refactoring

WHAT’S IN THIS CHAPTER?

  • Using code snippets
  • Creating your own code snippets
  • Refactoring code

One of the advantages of using an integrated development environment (IDE) over a plain text editor is that it’s designed to help you be more productive and efficient by enabling you to write code faster. Two of Visual Studio 2012’s most powerful features that help increase your productivity are its support for code snippets and the refactoring tools that it provides.

Code snippets are small chunks of code that can be inserted into an application’s code base and then customized to meet the application’s specific requirements. They do not generate full-blown applications or whole files, unlike project and item templates. Instead, code snippets are used to insert frequently used code structures or obscure program code blocks that are not easy to remember. In the first part of this chapter, you see how using code snippets can improve your coding efficiency enormously.

This chapter also focuses on Visual Studio 2012’s refactoring tools — refactoring is the process of reworking code to improve it without changing its functionality. This might entail simplifying a method, extracting a commonly used code pattern, or even optimizing a section of code to make it more efficient.

Although refactoring tools are implemented for C# in Visual Studio, unfortunately they haven’t been implemented for VB. To fill this hole in functionality in earlier versions of Visual ...

Get Professional Visual Studio 2012 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.