Refactoring is a mind-set of developing. Extract Method keeps your methods small. Both Bill Ryan, one of my partners, and I have joined many others in the discussion of refactoring. Although refactoring has been a hot topic in Java for years, and of late in C#.NET, I and others are pushing for it to become a hot topic with VB.NET developers also.
Having been a Visual Basic developer since the release of VB3, and a VB.NET developer since the release of Beta 1 of VB.NET, I have to confess that I have programmed many, many methods that were not modular, small, readable, and easy to maintain.
Extract Method is one of the key methodologies that are done both manually and through automated tools. That is one of the reasons that I began several months ago to develop NET Refactor. I needed a tool to help me clean up a lot of code. Extract Method was one of the first refactoring features that I began work on.
One of the problems in manually extracting a method is that you have to determine what variables must be passed to the extracted method, and how they are to be passed. After determing this, you may find that you are passing 5-10 or even more variables to the new method. You can do this automatically, with such tools as NET Refactor, but if you do, you may build a calling line and new method signature that look as confusing as the complexity of the large method from which you are extracting.
To solve the problem of passing a large number of variables, you might want to determne the variables that are needed in the new method, creat a Structure or Data Class Instance and then pass that single object to the new method. To that end, NET Refactor now has a new feature, Extract Object, which allows you to select a block of variables and automatically create either a Structure or instance of a Class. Obviously, when you write a very large method, you are adding variables in random order, and therefore extracting an object can be a frustrating process of cutting and pasting variables to get them into a one block that can be extracted into a Structure or Class. The NET Refactor feature, Reorder Variables, provides an automated method for reordering and grouping variables in a large function or at the class level. In a future release of NET Refactor, I plan to incorporate the functionality of Extract Object into the Extract Method feature. That will make the Extract Method feature even more powerful and easier to use.
I cannot overemphasize the importance of writing and keeping your methods small, functional, readable, and easy to maintain. NET Refactor has two other new features that will assist you in cleaning up your methods. Rename Local Variables and Rename Parameters will help you to make existing variable names and method parameters more meaningful.
I hope that you will consider refactoring as a mind-set to maintain while you are developing new code and as you are maintaining existing code. Also, keep in mind that you are not the only one that will ever have to try to understand your code.
Happy refactoring and give NET Refactor a test drive, only if you consider that your time is money, and the better producer you are, the more valuable and marketable you become!