Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Extract 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
netics Posted - Apr 25 2007 : 02:10:00 AM
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)

or

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

or

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




and so on...



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




5   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Nov 07 2014 : 10:07:34 AM
case=1492 is implemented in build 2052
feline Posted - Apr 25 2007 : 05:24:19 AM
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.

case=1492
sl@sh Posted - Apr 25 2007 : 04:07:39 AM
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.
netics Posted - Apr 25 2007 : 02:58:15 AM
bugfix//

hahahaha.

-_-;;;;;;

shameful T_T
bugfix Posted - Apr 25 2007 : 02:56:07 AM
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...

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