Chapter 8. Refactoring Code


IN THIS CHAPTER

  • Visual Studio Refactoring Basics

  • Rename

  • Extract Method

  • Extract Interface

  • Refactor Parameters

  • Encapsulate Field

Whether or not you realize it, if you are like most developers, you are always refactoring code. Every time you change your code to reduce duplication or rename items for the sake of clarity, you are refactoring. Refactoring is simply putting a name to a common development task. The strict definition of the term is, "A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior." That is, refactoring does not add features to the application. Instead, it improves the general maintenance of the code base.

The term refactoring has received a large amount of attention as of late. A number of good books have been written touting the many benefits of refactoring code as you are building your application. This is when you are closest to the code and thus able to quickly make these maintenance-type changes. Many of these books are on the subject of extreme programming. Refactoring has become one of the key tenets of the extreme programmer. In extreme programming your code base builds feature by feature to satisfy a series of tests. This can result in code that works wonderfully but does not look like it was designed as a cohesive unit. To combat this, you would be wise to go over the code base at frequent intervals and thus improve the general quality of the code (remove duplication, create common interfaces, rename items, put things into logical groups, and so on).

Perhaps because of all this attention, a new set of features has arisen inside code editors to aid with refactoring. These features have their basis in a real need. No developer wants to introduce errors into a relatively stable code base simply for the sake of improving maintenanceespecially when running a tight schedule. Imagine explaining to your manager or client that the large spike in bugs is a result of sweeping changes you made to the code to improve future maintenance and readability. We can be thankful that the C# editor inside Visual Studio 2005 provides a reliable set of refactoring tools. These tools let you make changes to the code base without the concern of creating more issues than you are solving.

Refactoring for the VB Developer

We are focusing this chapter on the refactoring tools built into Visual Studio 2005. These tools are strictly for the C# code editor. Fortunately, Visual Basic developers do have an option for refactoring. A third-party development house, DevExpress (www.devexpress.com), struck a deal with Microsoft to include a version of its product for all Visual Studio 2005 VB .NET developers. We cannot cover this tool in this book, but users should find many similarities between the two products.





Microsoft Visual Studio 2005 Unleashed
Microsoft Visual Studio 2005 Unleashed
ISBN: 0672328194
EAN: 2147483647
Year: 2006
Pages: 195

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net