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

 All Forums
 Visual Assist
 Feature Requests
 Refactoring : Delegation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

netics
Senior Member

30 Posts

Posted - May 20 2007 :  9:34:14 PM  Show Profile  Reply with Quote

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.

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - May 21 2007 :  04:50:16 AM  Show Profile  Reply with Quote
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?

Edited by - sl@sh on May 21 2007 04:56:54 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18755 Posts

Posted - May 21 2007 :  11:47:09 AM  Show Profile  Reply with Quote
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

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

netics
Senior Member

30 Posts

Posted - May 21 2007 :  7:32:09 PM  Show Profile  Reply with Quote
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.

Edited by - netics on May 21 2007 7:36:39 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18755 Posts

Posted - May 22 2007 :  06:14:55 AM  Show Profile  Reply with Quote
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.

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

netics
Senior Member

30 Posts

Posted - May 22 2007 :  7:19:40 PM  Show Profile  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000