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
 A seriously better refactoring tool for C++
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mordachai
Tomato Guru

USA
224 Posts

Posted - Jan 28 2014 :  2:55:57 PM  Show Profile  Reply with Quote
VA is awesome. It's indispensable.

However, it's c++ refactoring tools have remained basically static in scope & power for the last decade or more.

I find myself having to use sed / find&replace w/ regexes to do any real refactoring.

It's ridiculous. How often do I need to do the following source code transform:

object.function(arg1, ...)
to
function(object, arg1, ...)

Or vice verse... A freaking ton.

Or

function(arg1, arg2, arg3)
to
function(arg3, arg1, arg2)

Or something similar.

Or generally speaking, lots & lots & lots of "where this function is, take the first/second/third argument & transform it thusly..."

And I have to express this will convoluted bloviated grep syntax that doesn't really understand what constitutes a c++ symbol - which function references it should scope itself to, etc... all of which your software would know how to do.

I want a tool that lets me say "for every call to this function, do the following enhanced regex operation" - where the enhancements to regex would allow me to trivially talk about an argument... not have to write up a 32-character attempt to teach regex what a c++ argument is (which is nigh impossible to do - since an argument may be the result of an embedded expression, or involve indirection, dereferences, and casts). But again, your parser knows what a single argument is... it can parse the original function and its callers. So... I need tools that let me manipulate at that level of description instead of at the character-by-character barbaric what-year-is-this-seriously? level.

What do you think?!!!

I dare you: write something amazing!

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Jan 29 2014 :  12:42:29 PM  Show Profile  Reply with Quote
Are you aware of Change Signature refactoring? This command was seriously improved in VA 2007 and now capable of updating references and overridden methods in subclasses. So if you reorder, add, remove parameters, they will be reordered / added / removed at call sites and in overridden methods' signatures as well. This is a good start, isn't it?
Go to Top of Page

Mordachai
Tomato Guru

USA
224 Posts

Posted - Jan 30 2014 :  3:53:34 PM  Show Profile  Reply with Quote
I use change signature often - but until this week had not realized it could handle reordering of arguments.

That IS a nice feature.

Unfortunately, there is a lot of functionality left on the table.

It refuses to do a CS (change sig) on any overloaded function.
It is pretty restrictive about the changes I can make at any one time. Cannot both change a type and its name - have to do two separate commands to achieve that (it would be nice if it could do the two stage update itself).
And I really could use to have a way to invert free-function and method-call syntaxes: f(o, ...) <-> o.f(...).

Still, it's a tool I use heavily, so clearly it is useful in its current incarnation.

I'll list more specific requests as I bump into the lack of them. Still seems like a lot of grunge work could be handled by a smarter-than-grep tool, which would be hugely more versatile than simply trying to identify and build a specialized tool for N specific cases (such as the CS tool is).
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18942 Posts

Posted - Jan 30 2014 :  10:33:15 PM  Show Profile  Reply with Quote
What are you thinking of when you say a smarter-than-grep tool? Grep already exists in the IDE, do an IDE find or find and replace in regular expression mode. You have to use IDE regular expressions, which are a different format than usual, but this already exists.

Grep, or any search across files does not understand your source code, so won't know what to look for. Some of the restrictions you are seeing with Change Signature come from the need to parse your code, understand what we are looking at, and leave you with something valid at the end of it.

Overloaded functions are a perfect example. Combine overloaded functions with default parameters, and you cannot even rely on the number of parameters to tell you which overload is being called. True, this is an edge case, but its one we need to be aware of, and its going to trip up any simple regular expression search.

We are hoping to have Change Signature handle overloaded functions correctly one day, but its a tricky problem:

case=2164

Inverting free and member function calls is interesting, but also very open ended. Going in one direction, making the call a class member call, sounds fairly safe, since the parameter already exists, so we know the object that will do the call. But this is still likely to give you code that does not compile.

Going in the other direction is more messy, what if the function is being called directly, so internally by the class in question? Then the new first parameter becomes "this".

How general is this problem for you? Do you *always* want to swap out the first parameter, or is it "swap out parameter n"?

This sounds like it would be better handled as a separate pair of refactoring commands to me, rather than trying to add this complexity to Change Signature.

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

Mordachai
Tomato Guru

USA
224 Posts

Posted - Jan 31 2014 :  2:25:15 PM  Show Profile  Reply with Quote
What I really would like is a smarter search, and search & replace.

I want a grep-like tool - in that it should fully support some flavor of regex - preferably one that has a high fidelity with Visual Studio's regex parser.

However, it should also support non-standard VA-extensions which are smarter-than-regex.

[:idenitfier:]
[:argument:]
[:functioncall:]
[:class:]

I'm not sure what exactly would be best, but I'll try to come up with a few ideas.

See, the issue is try-to-come-up with a regex that correctly identifies the first argument to a function call:

f(a->(*b, *c).x*3.7+table[i], j);

What possible regex can you think of that would identify `a->(*b, *c).x*3.7+table[i]` as an [:argument:]?

VisualStudio used to offer things like [:i] (I think it still does, but they're too stupid. Literally. Too dumb to parse the above function call's first identifier or argument.

Even getting away from [:argument:] to say [:identifier:] - a.m_member - should resolve into a single identifier, not two identifiers. But getting regex to handle that?! ha ha ha.

Further, it becomes a nightmare to be able to construct the replacement string - having to work for a long time to produce a regex search string that finds the right patterns... and then have to go back and add grouping expressions so that I can build a replacement expression string that has the $1 $2 etc... again, these things become too complex for regex very quickly - because it wants to parse at the character level.

I need a regex that can do that AND parse at the symbolic level.

Your software understands things at the symbolic level. It can tell what is a whole expression. What is a whole identifier. What is a whole argument to a function call.

So... I want a search & replace tool where I can "speak" at a high level where possible, and only use character matching for the other parts.

I don't really even want to have to build up a regex to say "the comma and whitespace that comes between this argument and the next argument". Even building that regex is a major PIA, and one that can trivially go wrong if your method/function call spans multiple lines.

And just having to say a long dense complex string to properly match "whitespace<comma>whitespace" is lame, time-consuming, and takes away the focus from the job: transforming some old crummy code into something modern and correct.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18942 Posts

Posted - Jan 31 2014 :  5:53:38 PM  Show Profile  Reply with Quote
What sorts of things are you trying to achieve here? The problems you identify are all real issues, its sometimes very difficult to determine a parameter, or a function call. Once people start doing "clever" things with macros you can end up with situations that are very difficult to untangle.

This is actually why VA has a series of fairly specific and focussed refactoring commands, so that we can offer something well defined and helpful, and hide as much of this complexity as possible.

Extending the regular expressions like this does have a certain appeal, I find regular expressions very helpful myself, but they are also fragile and time consuming to get right, as you say, so I am really not sure this would get used much at all. It seems quite a lot of work for something most people just won't bother with.

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

foxmuldr
Tomato Guru

USA
402 Posts

Posted - Feb 03 2014 :  09:36:24 AM  Show Profile  Reply with Quote
quote:
Originally posted by Mordachai

VA is awesome. It's indispensable.



I agree completely. It should be a standard component of any Visual Studio install.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18942 Posts

Posted - Feb 03 2014 :  7:53:23 PM  Show Profile  Reply with Quote
Thank you for your kind words, we work hard to make Visual Assist a valuable and useful addition to the IDE.

zen is the art of being at one with the two'ness
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