Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Extract Constant
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Senior Member

30 Posts

Posted - Apr 25 2007 :  02:10:00 AM  Show Profile  Reply with Quote
it's similiar with Extract Method.

the purpose is encouraging to use symbolic constant,

for example:

if( value == -1 )     { /* do bla~~~ */ };

above code, show us the magic number.

now, select the "-1", and use "Extract Constant".

then prompt dialog for asking constant name, then

#define MAGIC_NUMBER (-1) (C style)


const int MagicNumber = -1; (C++ style)


const int SomeClass::MagicNumber = -1; (if possible, this is the best form for C++)

and so on...

int len = strlen("Replace Me!!");

Edited by - netics on Apr 25 2007 02:58:36 AM

Tomato Guru

324 Posts

Posted - Apr 25 2007 :  02:56:07 AM  Show Profile  Reply with Quote
Originally posted by netics

if( value = -1 )     { /* do bla~~~ */ };

above code, show us the magic number.

it shows a bug in first case :P

anyways, others might want enums...

Go to Top of Page

Senior Member

30 Posts

Posted - Apr 25 2007 :  02:58:15 AM  Show Profile  Reply with Quote



shameful T_T

Edited by - netics on Apr 25 2007 02:59:05 AM
Go to Top of Page

Tomato Guru

204 Posts

Posted - Apr 25 2007 :  04:07:39 AM  Show Profile  Reply with Quote
I like the idea. Personally, whenever I spot a literal - be it a character, number or constant string - somewhere in the code, then I always consider whether I shouldn't make it a constant of some sort. The question is however how VAX should implement such a feature.

1. Maybe it's possible to provide a refactoring menu on literals, providing the method 'make constant'. This would require VAX to gather at least three pieces of information from the user: (a) where should the definition be placed, (b) what kind of definition should be used (#define, const, etc.) and (c) how should it be named. Even after acquiring that information some kind of rename dialog should pop up that prompts the user to select which instances of the literal turning up within the code should be replaced, and which ones should stay.

2. Possibly a bit easier on behalf of the VAX implementers: any constant definition provides a refactoring method 'replace literals' that replaces any instances of the literal the constant is initialized with with the constant symbol itself. As above, a dialog should prompt the user to select those instances that should or should not be replaced.

Obviously, in both cases, if the contant definition is located within an implementation file, then only literals within that file should be considered. If the definition is placed within a header file, literals within all files that have this header within their scope should be considered.

Probably not trivial to implement, but if it could be done I would certainly appreciate it.
Go to Top of Page

Whole Tomato Software

United Kingdom
17821 Posts

Posted - Apr 25 2007 :  05:24:19 AM  Show Profile  Reply with Quote
I like this idea, at least the basic form of it. We are considering adding the refactoring "Introduce Variable", which is designed to introduce a variable into a function. If this worked on string / numbers then this would be a good start. Once you have the variable it is very easy to turn it into the #define, constant, enum, etc, that you want.

Lets wait to see this working before getting to excited about scanning the entire project for common strings / numbers. For numbers two different constants, with two different meanings, can have the same numeric value, so I can see possible problems if you start scanning to much code.


zen is the art of being at one with the two'ness
Go to Top of Page

Whole Tomato Software

2817 Posts

Posted - Nov 07 2014 :  10:07:34 AM  Show Profile  Reply with Quote
case=1492 is implemented in build 2052
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2021 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000