I had the good fortune to present on the topic of refactoring at the 2006 Great Lakes Great Database Workshop (GLGDW) hosted by Whil Hentzen. In this presentation I discussed using localized #Define statements (FoxPro's preprocessor directive) to implement the refactoring pattern "Replace Magic Number with Symbolic Constant."
#Define statements can also be used to hide a calculation that by itself doesn't communicate clearly what, exactly, the calculation is. For example, the code I started with looked like this (somewhat simplified):
If This.Value < Date() - 100 This.Value = This.Value + 100 * ( Int( Year( Date() ) / 100 ) ) Endif
This snippet of code is (smelling) ripe for Replace Temp with Query. Rather than going to the bother of creating a custom method just to hide the trivial complexity of this calculation, I decided a local #Define would work very nicely, and it even makes the code more efficient. Even though it's not important in this case, and even though refactoring doesn't explicitly improve optimization, this is a good example of how refactoring can result in more optimal code as a side affect. Here's the snippet refactored:
#define lnCenturyNow 100 * ( Int( Year( Date() ) / 100 ) ) If This.Value < Date() - 100 This.Value = This.Value + lnCenturyNow Endif
And, yes, I do realize I still have a "Magic Number," but that'll have to wait for a more pressing reason to change what's clearly (to me) a century.