Chapter 8. Code Snippets and Refactoring


  • 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 2010'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 2010's refactoring tools — refactoring being 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. In order to fill this hole in functionality in previous versions of ...

Get Professional Visual Studio® 2010 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.