|
Details |
Top Previous Next |
|
Localize Module Variables: This refactoring analyzes the way that private module-level variables are referenced,determines the optimum scope of each private module-level variable based on its usage within the module, and lets you customize and execute any/all the variable moves with great ease.
Localize Module Variable Example
Localize Module Variables is not an officially-catalogued refactoring, so far as this author knows, but it meets the definition of a refactoring: it should not change the behavior of your code. Here's how it works:
Additional "counter-example": if you are using a module-level variable as a "static" variable that is only referenced by one procedure, then CodeShine will recommend moving it to that procedure, which would probably not correspond with your intentions (TODO: click here for details and description of problems with VB Statics). For this reason, we recommend naming these variables in a way that indicates their function; e.g., m_stSuspendUpdates. With those cavaets in mind, this is a great tool for simplifying the structure of a module, especially if "the last programmer" wasn't too careful about encapsulation. It is also can be useful after you've made significant changes to a module - if you've deleted or consolidated several routines, for instance, you may now have one or more module-level variables that can be "localized."
If all of the suggested Actions are None, then that's an indication that all private module-level variables appear to be appropriately scoped; however, (as explained above), suggested Actions other than None are not necesarily indications of problems; they are simply indicate which variables to consider moving or deleting.
|