Author |
Topic |
|
Dans
Senior Member
Ukraine
45 Posts |
Posted - Nov 27 2007 : 09:28:01 AM
|
Hi,
Often i need to correct method parameters in declaration (in h file) during changing implemention (in cpp file) or correct implementation from declaration. Pessimistic steps are:
- cursor movements to parameter section,
- select parameters part,
- copy parameters part,
- cursor movements to method name,
- Alt+G,
- cursor movements to parameter section,
- select parameter section,
- paste,
- Navigate Back
I propose to create Visual Assist's command that provides parameter synchronization in single short-cut. When carret is anywere in method body and I press, for example, Ctrl+Alt+Y, method declaration/implementation is automatically syncronized. It will be awesome improvement during refactoring code.
For sure you should trap situations when there are overloads, but this can be done by additional popup like in Alt+G functionality
Thanks, Dans
|
Edited by - Dans on Nov 27 2007 09:45:47 AM |
|
jmihalicza
Ketchup Master
Hungary
66 Posts |
Posted - Nov 29 2007 : 06:14:35 AM
|
I am glad to see that it is not only my problem, I too hope there will be such a feature sometime. |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Nov 29 2007 : 5:37:51 PM
|
I am not sure I understand. Are you saying you have this situation:
class CTestClass
{
void memberFunction(int nHeader, int nHasOneThing);
};
and in the cpp file:
void CTestClass::memberFunction(int nCppFile, int nIsDifferent) { } If so you can simply use Change Signature on the function, and VA will then apply the parameter names you set in Change Signature to both the declaration and the implementation. |
zen is the art of being at one with the two'ness |
|
|
Dans
Senior Member
Ukraine
45 Posts |
Posted - Nov 29 2007 : 8:46:21 PM
|
quote: Originally posted by feline -skip- If so you can simply use Change Signature on the function, and VA will then apply the parameter names you set in Change Signature to both the declaration and the implementation.
Yes, i need to correct signature, but i propose to implement it more intelligent. There are advangades:
- Signature changed in editor and single short-cut correct it in definition/implementation depends on invoking place. Invoking place is etalon for signature
- You can keep multiline formatting. I think, many developers are not used change signature because it removes formatting and dialog is too plain (you have requests to improve it )
- After compile error: signature differ i can correct error in single short-cut
- As i examined "change signature" gets definition as etalon,
but usually signature changed in implementation and then corrected in definition. I propose get as etalon editing position. I assume that there are limitations if cursor in implementation (static, defaults) but this, i suppose, can be easily merged
- Change signature works only if carrent is over method's name. It because VA canges signature using symbol under carret and it can be method of another class. Really rare used... I propose to activate parameter synchronization everywere in method's scope it will save time instead of aiming to method name
Thanks, Dans |
Edited by - Dans on Nov 29 2007 8:53:16 PM |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Nov 30 2007 : 09:40:49 AM
|
Point 2 and point 3 conflict. If we have to consider the case that the signature on the implementation is wrong - wrong number of parameters - then we are going to have to change it to fix it. As soon as we change it we are running the current Change Signature command.
We cannot just add or remove parameters and preserve the formatting of the code without further work. Change Signature changing / loosing the formatting is a known problem:
case=1631
but it is actually a hard problem. It is easy to think up edge cases where simple answers do not work.
Change Signature picking up the parameter names from the declaration is also a known problem:
case=9327
but in your case this is more debatable. Using the sample code I posted VA cannot know which names you prefer. As soon as it picks names from one location it can be wrong half of the time, on average.
Running Change Signature from anywhere on the line is an interesting idea, but it raises some interesting questions. This means you can trigger Change Signature while the caret is in the middle of white space, or a keyword.
How come you are running into this problem so often?
Are you using VA's rename command to rename the parameter in the implementation? This will rename the references inside the implementation, but does not currently rename the declaration. This is on our list of things to change:
case=1140
and would stop this problem occurring in the first place. |
zen is the art of being at one with the two'ness |
|
|
Dans
Senior Member
Ukraine
45 Posts |
Posted - Dec 03 2007 : 03:01:13 AM
|
quote: Originally posted by feline
Point 2 and point 3 conflict. If we have to consider the case that the signature on the implementation is wrong - wrong number of parameters - then we are going to have to change it to fix it. As soon as we change it we are running the current Change Signature command.
So it why i posted my first suggestion about quick navigation: http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=6487. I can quick navigate to implementation/declaration and analyse where is the problem and then press synchroization shortcut.
quote:
We cannot just add or remove parameters and preserve the formatting of the code without further work. Change Signature changing / loosing the formatting is a known problem:
case=1631
but it is actually a hard problem. It is easy to think up edge cases where simple answers do not work.
Sorry, maybe i missed something and i don't have big experience in parsing C++ code, but currently i don't see serious problems if developer is not using macroses. From header:
class CTestClass
{
virtual void memberFunction(
int nHeader, // header of something
int nHasOneThing = 10 // 10 is default value
) const;
};
CPP result:
void CTestClass::memberFunction(
int nHeader, // header of something
int nHasOneThing // 10 is default value
) const
{
} Maybe you can post more difficult to parse samples?
quote:
Change Signature picking up the parameter names from the declaration is also a known problem:
case=9327
but in your case this is more debatable. Using the sample code I posted VA cannot know which names you prefer. As soon as it picks names from one location it can be wrong half of the time, on average.
It's not a problem, if i decided to change signature from current location it's equal to that i know what i do and i what parameters i need. In other case user should keep in mind why it uses different param names and decline from using change signature at all.
quote:
Running Change Signature from anywhere on the line is an interesting idea, but it raises some interesting questions. This means you can trigger Change Signature while the caret is in the middle of white space, or a keyword.
Yes everywere in white space or not over identifier, but for me prefer if Change signature will be invoked even if curor over identifier. I never use changing signature for class that i can't see at this time. Also you can apply this to other VA functionality: Add Similar Member, Create Declaration, Create Implementation, Move Implementation to Source File Document method, etc.
quote:
How come you are running into this problem so often?
Are you using VA's rename command to rename the parameter in the implementation? This will rename the references inside the implementation, but does not currently rename the declaration. This is on our list of things to change:
case=1140
and would stop this problem occurring in the first place.
I saw this rename problem, it really need fixing. Usually i need to add/remove several parameters or change everything
BTW, I suggested do not change current Change Signature functionality, but implement new. It's different from change signature: No dialogs shown, Can be invoked in any place of method, Gets prameters from current location
Thanks for answers and focusing on problem, Dans |
|
|
sl@sh
Tomato Guru
Switzerland
204 Posts |
Posted - Dec 03 2007 : 05:21:56 AM
|
quote: Originally posted by feline
I am not sure I understand. Are you saying you have this situation:
class CTestClass
{
void memberFunction(int nHeader, int nHasOneThing);
};
and in the cpp file:
void CTestClass::memberFunction(int nCppFile, int nIsDifferent) { } If so you can simply use Change Signature on the function, and VA will then apply the parameter names you set in Change Signature to both the declaration and the implementation.
This is a problem I occasionally encounter as well. The solution with Change Signature is unsatisfactory, because it appears to always fetch the signature from the declaration, but usually when I want to snchronize, I changed the implementation. This means I have to change the suggested parameter names in the Change Signature box again, to reflect the changes I already made.
Would it be possible to let Change Signature fetch the initial signature from the file it is called from instead of the declaration file?
There is also an apparent problem in Change Signature: If the declaration contains a macro (e. g. for _decl specification), then this macro will also be inserted for the implementation - which is wrong for _declspec! Ok, VA probably doesn't know what this macro is for, but in function declarations the only sensible use of macros usually is for _decl specifications - which mustn't be used inside the implementation files!
Example header file:
#define MY_API __declspec(dllexport)
//...
class CMyClass {
MY_API void foo();
}; Example implementation file:
MY_API void CMyClass::foo() {//compiler error in this line!!
//...
}
I realize that the moment VA stops copying macro symbols to the implementation signatures, some people will complain. However, I don't see any valid use for macros besides _declspec, and I always considered VA a tool that helps implement reasonable code! |
Edited by - sl@sh on Dec 03 2007 05:23:31 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Dec 03 2007 : 09:37:56 AM
|
This is going to take some replying to, so I am going to try and answer this one point at a time.
quote: Originally posted by Dans
So it why i posted my first suggestion about quick navigation: http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=6487. I can quick navigate to implementation/declaration and analyse where is the problem and then press synchroization shortcut.
I am now completely confused.
I see no obvious connection between having a navigation history of *more than* 20 places and jumping between the implementation and declaration of a function.
When I need to jump between the implementation and declaration of a function I use either alt-g to go directly to the function, or alt-o to jump to the matching file. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Dec 03 2007 : 09:46:18 AM
|
quote: Originally posted by feline
We cannot just add or remove parameters and preserve the formatting of the code without further work. Change Signature changing / loosing the formatting is a known problem:
case=1631
We are talking about different things. You said that your code does not compile. The code:
class CTestClass
{
void memberFunction(int nHeader, int nHasOneThing);
};
void CTestClass::memberFunction(int nCppFile, int nIsDifferent) { }
will compile quite happily. Which is why I assumed you are talking about code like this:
class CTestClass
{
void memberFunction2(int singleParameter);
};
void CTestClass::memberFunction2(int firstParameter, int secondParameter, int thirdParameter) { }
which does not compile, since the two signatures are different. If you are talking about something else again then I don't know what you are talking about.
Preserving the formatting when running Change Signature, consider this example:
class CTestClass
{
void memberFunction3(int longParamaterNameHere, int n1, int n2,
int n3, int n4,
int n5);
};
void CTestClass::memberFunction3(int longParamaterNameHere,
int n1, int n2, int n3, int n4, int n5) { }
There is no obvious and reliable method to preserve the formatting when you add or remove a parameter. Firstly note the formatting is quite different between the implementation and declaration, which is going to cause problems. Secondly notice that adding or removing parameters breaks both formatting instances. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Dec 03 2007 : 10:00:12 AM
|
quote: Originally posted by Dans
It's not a problem, if i decided to change signature from current location it's equal to that i know what i do and i what parameters i need. In other case user should keep in mind why it uses different param names and decline from using change signature at all.
both you and sl@sh are asking for Change Signature to pick up the names from the current location. But consider this simple example:
class CTestCode
{
int memberFunction4(int nHeaderParamName);
};
int CTestCode::memberFunction4(int nCppParamName) { }
static void callFunction()
{
CTestCode foo;
foo.memberFunction4(32); // trigger Change Signature HERE
}
At this point there is no "current" set of parameter names to pick up. A second example:
class CTestCode
{
int memberFunction5(int);
};
int CTestCode::memberFunction4(int nCppParamName) { } sometimes there is no parameter name in the header or in the cpp file to pick up. This is actually where the bug report for Change Signature picking up parameter names came from.
Picking up the names from the current location makes sense some of the time, but not all of the time. I have put in a feature request to see what the developers make of this:
case=10283
Notice that you can trigger refactoring operations in places that you might not expect. As soon as we start allowing you to trigger them on white space we are going to run into problems where VA's parser does not know what you are trying to operate on.
Dans I appreciate you want a specific command to do a specific thing, but I am still concerned by your reference to code not compiling. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Dec 03 2007 : 10:10:20 AM
|
quote: Originally posted by sl@sh
There is also an apparent problem in Change Signature: If the declaration contains a macro (e. g. for _decl specification), then this macro will also be inserted for the implementation - which is wrong for _declspec! Ok, VA probably doesn't know what this macro is for, but in function declarations the only sensible use of macros usually is for _decl specifications - which mustn't be used inside the implementation files!
If only this was true
We have been getting regular bug reports about code like this:
class CTestClass
{
void memberFunction5() MACRO_HERE;
};
and variations on this theme.
There is also the interesting case of:
#define CLASS class
CLASS CTestClass
{
// members here
};
and yes, that really has come up. Plus all of the cases where macro's are used as types.
I am not sure there are any simple answers here. A quick search of our bug database for "__declspec" threw up:
class bugCreateImplementation
{
static void __declspec(noreturn) dllExportedFunction();
};
and the even more lovely:
#ifdef FIREAPI_DLL_BUILD
#define FIREAPI_DLL_SPEC __declspec(dllexport)
#else
#define FIREAPI_DLL_SPEC __declspec(dllimport)
#endif which unfortunately presents some serious problems for VA trying to evaluate the macro, especially when you throw in:
#ifdef UNIX
#define FIREAPI_DLL_SPEC
#endif
I think this needs discussing as a separate thread, this thread is getting confusing enough as it is. |
zen is the art of being at one with the two'ness |
|
|
Dans
Senior Member
Ukraine
45 Posts |
Posted - Dec 03 2007 : 11:41:37 AM
|
quote:
--skipped-- I am now completely confused.
I see no obvious connection between having a navigation history of *more than* 20 places and jumping between the implementation and declaration of a function.
Hm, what 20 jumping places? I suggested to quick jump between declaration and implementation. Sorry if my posts confuses someone - bad english :(
quote:
When I need to jump between the implementation and declaration of a function I use either alt-g to go directly to the function, or alt-o to jump to the matching file.
Yes i do it everytime and i found it not quite effective. I need to place carret over method name for every jump (usually get mouse in hand). It tooks about 2-5 seconds everytime. In case when method name is not visible it can took more time depends on how many lines you should scroll. Alt-G always depends on symbol under carret and usually needs additional choise from popup... In "Quick Navigation suggestions" thread i proposed way how to simplify and extend current navigation. It really works and useful. Sorry if i repeat oneself.
Thanks, Dans |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Dec 03 2007 : 1:37:13 PM
|
In the quick navigation thread can you try and post a simple code example to explain what you want, and are trying to do? I simply don't understand what you are looking for. I am thinking in different terms to you, I think this is the problem.
I want to avoid getting bogged down in quick navigation in this thread as well, since the whole updating function signatures is complex enough as it is |
zen is the art of being at one with the two'ness |
|
|
sean
Whole Tomato Software
USA
2817 Posts |
Posted - Nov 18 2013 : 3:17:30 PM
|
Change Signature was overhauled in build 2007. case=9327 is fixed in build 2007. |
|
|
|
Topic |
|
|
|