I have a literal bit of data (an int, a string, etc.) which I am going to need to use more than once. Usually I end up typing the value inline, and then later extracting it as a constant for that translation module.
e.g.:
RegistryKey keyOpenWith(keyClass.OpenSubKey(_T("OpenWithProgids"), KEY_READ));
CStringArray openwiths;
keyOpenWith.EnumerateValueNames(openwiths);
for (int j = 0; j < openwiths.GetCount(); ++j)
if (Contains(our_progids, openwiths[j], case_insensitive_equal_to))
our_openwiths.push_back(std::make_pair(classes[iClass], openwiths[j]));
It would be great to have a Refactor: Extract constant.
That would simply allow me to name it (and set its type - much like extracting a method), and then it would move the definition to the file header? or just before the method/function body? Or perhaps give me a scope option as to whether to make it visible only in this function, or translation module, or class, etc.
I envision something like this:
const TCHAR kOpenWithProgids[] = _T("OpenWithProgids");
And further down in the code...
RegistryKey keyOpenWith(keyClass.OpenSubKey(kOpenWithProgids, KEY_READ));
CStringArray openwiths;
keyOpenWith.EnumerateValueNames(openwiths);
for (int j = 0; j < openwiths.GetCount(); ++j)
if (Contains(our_progids, openwiths[j], case_insensitive_equal_to))
our_openwiths.push_back(std::make_pair(classes[iClass], openwiths[j]));