Refactoring is a technique to restructure code in a disciplined way. This article suggests code analysis and visualization tools to help in the refactoring process.
Refactoring means modifying existing source code in a structured and incremental way. In refactoring, the behavior of the code is not radically changed. Refactoring promotes reuse as the refactored code is potentially easier to use in another context or for another purpose.
Refactoring is a generic programming technique that is not tied to a specific implementation language. We refer to the Refactoring web site of Martin Fowler for the various refactoring techniques.
Use of Project Analyzer to refactor VB code
Project Analyzer is a tool that helps refactor existing Visual Basic code. It is useful in two ways.
Firstly, Project Analyzer helps to identify code that would potentially benefit from the refactoring techniques.
See also the full set of code review rules supported by Project Analyzer.
Secondly, Project Analyzer can also automatically perform a part of the refactoring. The auto-fix feature of Project Analyzer Enterprise Edition is able to automatically modify source code according to predefined rules. At this time, Project Analyzer supports automatic encapsulation of class variables as property Get/Set/Let.
In most cases, refactoring is best done manually, because code changes need human consideration. Automated changes are meant for routine tasks only.
Visustin - Refactoring with flow charts
Another tool that is beneficial in the refactoring process is Visustin. This utility displays a flow chart for a given piece of executable code, be it in Visual Basic, C/C++, C#, Java, Pascal, COBOL or a number of other major programming languages.
Logic errors easily appear in code that contains nested conditionals, loops and jumps. A flow chart displays program logic in a more comprehensible manner, not tied to the order that the underlying code is written in. By reading source code and flow charts side by side you can find logic flaws that could be left undetected by looking at the code only.
Besides error detection, a flow chart helps in finding ways to refactor code in a manner that is potentially more readable or more optimized. Visual interpretation of code can reveal patterns that are not easy to see in the source.