My refactoring heuristics (4)

Posted by Albert Gareev on Jul 05, 2010 | Categories: ImplementationNotes

“Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a ‘refactoring’) does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it’s less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring. “

Martin Fowler

Test Automation / VBScript / Refactoring

Subject: Function Library

Heuristic: Group Constants Together

1) If you have a few constants (or hard-coded values) used in private or public functions within a function library, move them to a heading section, and re-declare as private or public, depending on the scope.

2) If you have a significant number of constants used by functions from different libraries, consider creating a separate library to keep all constants together in one place.

3) If you have a set of constants, for instance, like test log messages, group the entire set in an array or Dictionary type of structure.

Heuristic: Redundant Functions

Review mid-level function libraries, and move duplicating low-level functions away.

Examples: math operations, string or date functions.

Heuristic: Unit Tests

Keep the code you wrote to test or debug your functions [in a separate library]. Even if it’s written “dirty way”, it still might be better than write from scratch next time.

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.