Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Refactor: Move inline data to named constant

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Mordachai Posted - Jun 09 2010 : 11:40:36 AM
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]));

5   L A T E S T    R E P L I E S    (Newest First)
Mordachai Posted - Nov 07 2014 : 10:54:12 AM
You guys rock! :D
sean Posted - Nov 07 2014 : 10:08:15 AM
case=1492 is implemented in build 2052
Mordachai Posted - Jun 22 2010 : 10:54:46 AM
It would be really sweet if it would automatically replace all occurrences of the selected data with the newly named & created variable. ;)
peterchen Posted - Jun 22 2010 : 03:52:50 AM
I wish(ed) for this, too, and yes, just making the extraction to a local variable would solve the "tricky" part. Fixing the constness, moving it to another place etc. is easy in the editor.
feline Posted - Jun 14 2010 : 11:10:41 AM
We are looking into adding a feature like this at some point:

case=1492

At first it might just extract a local variable, but it will be fairly quick and easy to convert this local variable into a const, if required.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000