T O P I C R E V I E W |
netics |
Posted - May 20 2007 : 9:34:14 PM There is a lot of necessity to code delegation. And it's such a bothering job.
How about adding Refactoring : Delegation feature?
It functions like this...
--> Code
bool IsActive(uint index);
--> Select Delegation Menu
--> Dialoge pop up. Type delegator name. ex) p
--> Code Changed to
bool IsActive(uint index) { return p->IsActive(index); }
One more.
Generally, delegation method is many.
It will be convenient to change many method at once.
|
5 L A T E S T R E P L I E S (Newest First) |
netics |
Posted - May 22 2007 : 7:19:40 PM About delegator selection, you miss the line of my first post.
"--> Dialoge pop up. Type delegator name. ex) p"
Like other refactoring, DIALOGE can be used.
For flexibility of slightly different method name, ALSO DIALOGE can be used.
The input entry "method name" of Dialoge can be filled by default value as same name.
About using macroes of IDE/Editor. Hey, AutoText is also macro and it recognizes C++ syntax.
So, it certainly becomes more useful tool for languages than others. Yes, it will not be EASY. I didn't request "Please make it until tomorrow~"
Not for only many delegatoin code typing, there sometimes exist 1~2 delegation in many class. Automating this will help too.
|
feline |
Posted - May 22 2007 : 06:14:55 AM autotext, I was looking at your example, which only has one parameter. If you are going to be applying this to many parameter functions then autotext is a less helpful answer. The same statement applies to a regular expression find and replace.
We are considering allowing refactoring "tokens" in non refactoring autotext entries, which if done, might help here:
case=3204
However this would not be a complete solution.
"Being clever", you mention adding either dot or -> after "p" which is fine, but this assumes that the class in question has exactly one member variable. What happens when the class in question has 6 member variables, of different types?
Simply saying "check which member type implements the function I am working on" does not work when you find that 3 of the member variable types implement this function. What happens when the function you are creating, or calling, has default parameters, or a different number of parameters?
Do you see what I am getting at here? Experience shows that "simple" refactoring operations tend to be more complex than you at first think.
Do you have a lot of code like this? In this sort of situation I would normally derive one class from another, so there is no need to write these functions by hand.
Personally I would tend to open the header file in VIM and use a VIM macro to generate these functions, simply because I am more familiar with VIM macro's than IDE macro's. However a simple macro would assume one parameter, and a simple type. |
netics |
Posted - May 21 2007 : 7:32:09 PM sl@sh : Macro is really not good. You have to type every parameter. It don't have much advantage than just typing with autoComplete.
feline : I don't think 'Official Delegation' make people expect really clever action. we are programmers. we know what computer can do and what can't.
rules are simple.
- If method return parameter is not void, Add return - Print delegator name - Print '.' or '->' (VA is already able to do this. If it can't be automatic, then just input information about delegator is pointer or not) - Print method name + ( + parameter1 name + , + parameter2 name + ... + );
It's all. so deterministic.
and I couldn't understand how can you archive this with AutoText. Can you explain me?
Problem about selecting many delegation method at once may be resolved by selecting just one class.
For all methods, in the selected class If it don't have implementation, then make delegator.
|
feline |
Posted - May 21 2007 : 11:47:09 AM sl@sh I put in a feature request myself to allow several methods at once to be effected via refactoring shortly after it appeared
netics if we assume that the function and parameter are the same then I am leaning towards an autotext entry myself. We are working on default values for autotext prompting variables, which would help here. All you would need to do is copy the function name which can be done with CTRL-W, CTRL-C in VS2003, VS2005 and fill this in when prompted, along with the variable name.
To make a official refactoring for this could raise all sorts of questions, especially when people want VA to get "clever" and read their minds.
If you were feeling brave you could probably do this with a regular expression search and replace. using capture groups to pick up the function and parameter name |
sl@sh |
Posted - May 21 2007 : 04:50:16 AM Methinks a macro would work better than refactoring for this. Normally, delegation happens for a number of methods within a class, and the call is delegated to a call of a member attribute's method of a similar (if not equal) name. If you write a macro for the class such calls are delegated to, you will catch all methods from dependent classes using delegation, and you will only have to press one short-cut for each function.
Refactoring however not only requires you to wait for the refactoring icon to appear, it also requires additional input for *each* delegation instance! This would only be better than macros if you have a lot of "basic" classes that require dependent classes to mostly delegate, and there is only a very small number of such methods in each basic class. In that case you would have to copy/modify your macro very often. Still, I don't think that will happen a lot.
Refactoring multiple methods at once would require the selection of those methods and applying refactoring on those. This would probably be nice for a number of other refactoring as well, and I would appreciate such a possibility. Until then I don't see a real advantage in having a "refactor delegate" function. Especially since what you suggested could probably done with custom VA Autotext already.
OTOH, if you really have a lot of delegation on your hand, maybe you should consider using more in the way of inheritance? |
|
|