Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Refactoring for Everyone Part 1
 »  Home  »  Visual Studio 2005  »  Refactoring for Everyone Part 1
Refactoring for Everyone Part 1
by Dmytro Lapshyn | Published  02/23/2006 | .NET Newbie Visual Studio 2005 | Rating:
Dmytro Lapshyn

Dmytro Lapshyn works as a CTO for Validio Ukraine, which is an official partner of Validio Software, LLC. He previously worked as a programmer in a volunteer student scientific and production group "Programmist" of Kharkov Technical University of Radio-Electronics.

During more than 7 years of his programmer career Dmytro has developed various applications including desktop, client-server and Internet development. He has been working with Microsoft technologies since 1998 and has been developing with Microsoft .NET since the Beta 2 release in 2001. His primary areas of expertise are Visual Basic, ASP, COM+ and .NET.

Dmytro is 27 years old and lives in Kharkov, Ukraine. He has a Bachelors and a Masters degree in Computer Systems Security from Kharkov Technical University of Radio-Electronics.

Company Profile

Founded in 1992, Alis Software successfully operated in software development market for 5 years. In 1997 the company was acquired by Miik Ltd and became its Information Technologies Division. Three years of flourishing accompanied by the dynamic growth made the division the priority of the company business and since 2000 Miik Ltd. almost entirely proceeded to producing software, computer graphics, and Web applications in partnership with foreign and national companies for clients both in Ukraine and abroad.

In summer 2005, Information Technologies Division of MIIK Ltd. was reorganized into Validio Ukraine.

Validio Software provides outsourced software development services to high-tech companies and businesses that rely on technology. Based in Seattle, Washington, Validio's services include design, management, and implementation of complete projects using experienced development teams, as well as providing skilled development resources for customer driven projects. By maintaining staff of qualified software developers and experienced project managers in both the U.S. and Ukraine, Validio offers its clients technical expertise that is both scalable and cost effective.


View all articles by Dmytro Lapshyn...
Refactoring for Everyone Part 1

You Are Very Likely To Have Done It Before

Even though my Microsoft Word 2003 has just underlined it with the red squiggle, the word “refactoring” is quite well-known nowadays. Even if you have never programmed in Smalltalk (the concept was born in the Smalltalk world), you might have heard or read it here or there – well, several lines above at the very least. I say 'at the very least' because refactoring is gaining popularity in the .NET world – to the point where Microsoft has decided to introduce it in Visual C# 2005.

However, I guess there are many developers who believe it is something they have never tried to do and if they have to, there’s yet another new concept to learn. Well, I have some good news for them: not really.

As unbelievable as it may sound, all of you are very likely to have refactored your code a number of times in your programmer’s career. Surprised? OK, have you ever done one of the following:

  • Devised a more appropriate name for a method or a parameter and then searched and replaced the old name everywhere in the code?
  • Added a new parameter to a method of a class and then edited all the places in the code where the method is called and passed in a value for that new parameter?
  • Taken a piece of code and moved it to a separate method to make it reusable or to just make the code more readable?

Even if you have never done exactly these things, I think you will have got the idea anyway. I am talking about the sort of changes to code that neither add new features nor fix defects, but rather facilitate both of the above. Such changes can be anything between local and profound, but usually can be performed (and are performed from time to time) by any skilled software developer.

The Simple Secret of Popularity

So, if the subject matter is something almost every programmer has done before, what makes it so popular nowadays? Didn’t software developers want to improve their code in the past? No, we all are pretty sure they did and actually made their code better when the need arose. However, what they lacked was a systematic approach and means of sharing the code reengineering techniques.

If you think about it, all this code reengineering can be boiled down to a fixed number of modifications, each serving a specific purpose. Let’s take adding a new parameter as an example. You can easily guess the purpose of this particular modification: to pass additional information the method requires from the caller. The same is true for renaming a method - the purpose is to make the name more descriptive. Moreover, one can write a detailed, step-by-step instruction for either of these modifications (as well as for any other of that sort). As an exercise, you can try to come up with the purpose and possibly the instruction for the second example above, moving a piece of code to a separate method.

Now, what if we were to take the purpose, the description of every known modification and the relevant step-by-step instruction and put them all together in some kind of a cookbook? Well, that’s practically what Martin Fowler, one of the founding fathers, did for his famous book, the lion’s share of which is the catalogue of the most widely used code improvement techniques. A number of benefits ensued from publishing the catalogue:

  • Unified, well-known names for each of the techniques that facilitate communication and knowledge transfer.
  • Succinct but precise descriptions of applicability enabling you to check whether a particular code modification is appropriate for your needs.
  • The large variety of techniques suggests improvements to those parts of your code that you would never think could or should be improved.

And that’s what, I believe, allowed refactoring to gain so much popularity among software developers – an established framework for code reengineering offering off-the-shelf field-tested and reliable recipes that save time and effort and greatly reduce the number of potential problems.

Visual Basic Is Invited!

Some of you might have found that most refactoring examples are in Java, C++ or in C#. And this is for a good reason. All these languages are more or less close to each other, and there’s a culture of pure object-oriented programming, especially in the Java community. The tools are also a major contributing factor. Quite a number of solutions for Java developers have been around for a while, and there is also noticeable support for C# with major players on the market - Microsoft has introduced code reengineering in Visual C# 2005.

VB .NET is, however, a different story. Its syntax is very different, and, according to Tom Archer, many VB programmers have difficulties understanding C# or C++ code. Nevertheless, VB .NET is no less suitable for the code improvement! Moreover, even in VB6 (or VB.OLD, as some people tend to name it), you can employ many of these techniques, probably even more than you can currently think of. Still, if you come from the VB6 background, you might be more comfortable if you start from the techniques that do not require previous object-oriented experience, as these are the ones you are most likely to apply first. And as your learning progresses, you will discover new depths of the object-oriented power of the next generation of the Visual Basic language.

Speaking of tools that would enable code reengineering in VB .NET, take a look at SubMain’s CodeItOnce. In the next part of the series, I am going to give you several examples of improving existing VB .NET code with the help of this tool. You can think of it as a small hands-on code reengineering lab which demonstrates the structured approach to making certain well-known modifications such as adding a new parameter.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:3.57894736842105 out of 5
 19 people have rated this page
Article Score15420
Sponsored Links