CodeShine
The CodeShine program is an example of a more typical refactoring process. This third-party utility also installs as an add-in to the VB 6 development environment and offers help in automating four standard techniques:
- Extract Method
- Introduce Explaining Variable
- Extract Function
- Localize Module Variables
In contrast, the "free" Refactor! tool (reviewed below) offers about fifty and the "Pro" version has seventy-five.
To see how well CodeShine performed, I picked on About Visual Basic's VB 6 TicTacToe program. At the top of the code, there is a short double nested loop that does nothing but clear the TicTacToe playing grid.
' Get ready to play another game
Sub InitPlayGround()
Dim i As Integer
Dim j As Integer
' Erase any playing grid symbols
For i = 1 To 3
For j = 1 To 3
lblPlayGround((i - 1) * 3 + j - 1).Caption = ""
iXPos(i, j) = 0
iOPos(i, j) = 0
Next j
Next i
End Sub
The idea behind Extract Method is to simply replace this simple initialization routine with a subroutine and a call that does the same thing.
Here's the end result after using CodeShine:
' Get ready to play another game
Sub InitPlayGround()
ClearGrid
..........
Private Sub ClearGrid()
Dim i As Integer
Dim j As Integer
' Erase any playing grid symbols
For i = 1 To 3
For j = 1 To 3
lblPlayGround((i - 1) * 3 + j - 1).Caption = ""
iXPos(i, j) = 0
iOPos(i, j) = 0
Next j
Next i
End Sub
As you can see, the process is one that you could do on your own. But CodeShine includes some integrated error checking to guard against mistakes and automates the process.
"Introduce Explaining Variable" simply substitutes a meaningful variable (like "summer_season") for confusing "magic numbers" in the code (like 6, 7, 8 for June, July, August). Localize Module Variables checks to see if variables need to be local or global (or are needed at all) and makes the appropriate adjustments.
The good news is that CodeShine has an easy to use interface and direct, straightforward functions. The bad news is that it unfortunately still seems to be a "work in progress". While testing the system, the add-in code crashed for a variety of different reasons. But I encourage you to try out the system yourself. You can, at least, learn some basic refactoring techniques just by testing it. Download the free trial from the CodeShine web site.

