1. Computing

Programmer Hell is spending eternity maintaining your own code.

When you're deeply involved in writing it, the structure of your code seems so logical. If you're forced to return to it a few years later, a lot of us want to say, "Who wrote this awful mess!" That's why there are "refactoring" tools and techniques.

A new article reviewing five Visual Basic refactoring tools has been added to the site. The illustration shows a graph of part of About Visual Basic's TicTacToe game created using the Project Analyzer tool.

These tools were selected to demonstrate the wide range of techniques that might come under the "refactoring" heading. They span the whole range of Visual Basic from VB 6 to VBA to VB.NET and they even include some ideas that many programmers wouldn't call refactoring.

There is already one comment about the article. The author of one of the tools, CodeShine, sent me his review of my review. I added it by permission as a comment to this blog.

April 4, 2007 at 2:36 pm
(1) visualbasic says:

1) Honestly, it makes little sense to me to compare CodeShine to Refactor! as if the user can/should choose one or the other – Refactor! works with .NET, and CodeShine works with VB6. They don’t share a target platform. And counting refactorings might be some measure of value, but the value of these refactoring is not distributed anywhere near uniformly – personally, I find that Extract Method and Introduce Local are 90% of what I ever need. Hey look, I’m a Refactor! fan and customer, but that doesn’t affect my need for CodeShine.

2) Maybe I don’t get it, but calling Aivosto Project Analyzer a “professional refactoring system” is a bit of a stretch to me, since it doesn’t do any refactoring. There are many fine tools for working with VB6 code, and I wouldn’t recommend to anyone that CodeShine be his/her only add-in, or even the first one. CodeShine is, as far as I can tell, complimentary to the functionality of every other add-in on the market, providing functionality that is simply unavailable through any other means.

3) I think that your example of refactoring makes Extract Method look both pointless and trivial, which I believe (vested interest notwithstanding) is a very distorted view.

For instance, you could have selected the inner loop to extract, and renamed the i parameter in the Extract Method dialog, giving you:

' Get ready to play another game
Sub InitPlayGround()
Dim i As Integer

   ' Erase any playing grid symbols
   For i = 1 To 3
    clearRow i
   Next i
End Sub

Private Sub clearRow(row As Integer)
Dim j As Integer

For j = 1 To 3
    lblPlayGround((row - 1) * 3 + j - 1).Caption = ""
    iXPos(row, j) = 0
    iOPos(row, j) = 0
Next j

End Sub

This at least demonstrates one of the subtleties of Extract Method – pulling the declaration for j into the extracted routine, but leaving the declaration for i back where it belongs.

You could have chosen other code that makes the complexity of the task evident: If you had selected code with an “Exit Function” embedded in it, you would have seen CodeShine write new code to wrap the extracted code properly so that the existing behavior is preserved (cut-and-paste would not do that). If you had selected code containing an assignment to a function name to extract, CodeShine would have handled that elegantly as well. Or, if you had selected a bit of code in a more complex routine, CodeShine would have made the dependency of that portion of code on the surrounding locals and parameters obvious in a way that visual inspection might not.

– email from Warren Sirota, author of CodeShine

September 1, 2008 at 1:45 am
(2) name says:

Good day!,

September 10, 2009 at 3:36 pm
(3) sandrar says:

Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

January 23, 2012 at 9:36 am
(4) Ali says:

I refactored a solution I was working on, I was able to clean up a lot of lines and reused more code.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>
  1. About.com
  2. Computing
  3. Visual Basic

©2014 About.com. All rights reserved.