KnowDotNet

Do VB.NET Developers Know About Refactoring? In C# it's the Rage!

VB.NET Developers, Don't Miss Out!

by Les Smith

Do VB.NET Developers Know About Refactoring?  Refactoring should be a mastered discipline regardless of platform, Java, C#, VB.NET,C++, JS.NET.  I searched the web today for the word Refactor, and Google reported approximately 208,000 hits.  It seems thousands of developers and authors have something to say about refactoring.  

There is a question out there, "Do VB.NET Developers know what the word "refactor" means?  I have read an article, which shall remain anonymous here, that Microsoft might be reticent to use the word Refactor on the menu of future Visual Studio .NET IDEs, when VB.NET is the language of choice.  Supposedly, and I'm not quoting a Microsoft source, rather someone else who said it about them; they think that the average VB.NET developer would not know what it means.  At the same time, refactoring is the current rage with C# developers.  Guess what?  It's been the rage with Java developers for a long time too.

Having been a VB developer for well over 10 years, I find it hard to believe that we don't know what refactoring means.  I surely don't intend to start a flame war here, but I use C# and VB.NET, and most postings I read from Microsoft and the Newsgroups say that by and large, the choice between the two languages is a matter of preference.  In my humble opinion, both have their strong points, and I like things that C# has that VB.NET doesn't, and vice-versa.  

I say all of that to say this; VB.NET developers are not pampered, and C# developers are not superior.   Therefore, I expect VB.NET developers to know about refactoring.  Refactoring is a disciplined methodology that is a natural part of the good developers skill set.  At the risk of repeating myself, I will quote my first article on
Refactoring, Part I.  Refactoring is an organized methodolgy for changing the internal appearance and organization of your code without altering the external behavior, except as the refactoring may cause your code to perform better.  

Moving past the formal definition of refactoring, I want to bring it down to what it really means to me.  I tried to set forth some of the main goals I have in refactoring in my earlier articles on the subject (see Part II or Part III).  In this article, I will say that it simply means to keep my code clean, tight, organized, and manageable.  

Additionally, refactoring is not something that I do after I finish a Class, Form, or Project.  Refactoring is something that I think about while I am developing.  When I add a new Class or Form to my project, I may add some regions (automatically with NET Refactor), such as the following:

#Region " Class Level Variables & Properties "

#End Region
#Region " Private Methods "

#End Region
#Region " Imports "

#End Region
#Region " Form & Control Events "

#End Region

As the Class or Form code is developed, I may add special Regions that describe and organize the methods into logical blocks of code.  in my estimation, if you have more than a half dozen methods of any size, you must utilize Regions.  Regions allow me to have a myriad of methods, some of which will inevitably be more than the hypothized 20 line limit (see Refactoring, Part I).  Some classes will be well over one to two thousand lines of code and comments, but with Regions collapsed, I am not overwhelmed by the size of the class.

So much for Regions.  I am currently into Refactoring Methods.  This is normally called Extract Method.  It simply means to look at methods that have grown too large to be manageable, extract one or more logical blocks of code, and create new, smaller methods from them.  To do this manually, you will have to examine the context code to determine the variables that must be passed to the new methods that you are extracting.  NET Refactor automates this refactoring process.

Well, I have run out of space for one article once again.  I just want to re-emphasize that refactoring is a required way of thinking for VB.NET developers every much as C# developers.  In a future article, I will go into the subject of Renaming.  By the way, try a 15 Day Free Trial of NET Refactor.