Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Small But Useful Enhancements to Sort Lines

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
membry Posted - Sep 14 2009 : 02:55:47 AM
Part of the challenge of a large legacy C++ project is large classes with large numbers of methods and members. Think 100+ at the top end of the spectrum. In the short term, we are sorting large lists and blocks of code prior to refactoring. VAX "Sort Selected Lines" is helpful. But limited. Would be nice if it could be enhanced in future versions. Not MS Excel type of sorting. But the ability to ignore qualifiers would help in sorting member lists and constructor initialization lists so that members are in the same order in both places. Even being able to sort on the 2nd or 3rd word would be helpful. Also the ability to sort on the 1st (or 2nd) capital letter so that getX, setX, getY, setY methods could be sorted in order.
29   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Jul 18 2016 : 10:52:01 PM
case=10239 is implemented in build 2107.
accord Posted - Oct 07 2009 : 2:37:55 PM
quote:

The annoyance is that its a distraction and oftentimes I'm typing the correct code but the "intellisense" is completing it to the wrong code based on keystrokes from the correct code.


We have solution for this. First, turn off these:

VA Options -> Advanced -> Correction -> Repair case
VA Options -> Advanced -> Correction -> Convert dot to -> (only in C/C++ files)
VA Options -> Advanced -> Listboxes -> Selections committed with: Any character not valid in a symbol

After that, modify this registry setting to turn off accepting member listboxes with any character:

https://docs.wholetomato.com?W371

This is an improvement over default intellisense, since you cannot turn off this behavior without Visual Assist.
This way, you don't have to turn listboxes off completely, but you can if you wish

quote:

Worse, the suggestion boxes often obscures code that I'm looking at as a reference for the code I'm writing.


If you hold down ctrl key then then listbox becomes transparent, so you can see the code through it (I'm not sure whether it works with older IDEs)
legalize Posted - Oct 06 2009 : 7:44:13 PM
I've been spending time in the Xcode debugger the past few days and have had very little time to spend in Studio, which I much prefer over Xcode.

I agree that intellisense is a preference, which is why I need an option to turn it off :-)
feline Posted - Oct 06 2009 : 7:06:01 PM
I have worked in editors with intellisense, without intellisense, and somewhere in between, and personally I find the intellisense to be very helpful, but it is a matter of personal preference.

Does turning off this option fix the remaining listboxes for you?
legalize Posted - Oct 06 2009 : 4:47:10 PM
The annoyance is that its a distraction and oftentimes I'm typing the correct code but the "intellisense" is completing it to the wrong code based on keystrokes from the correct code. So then I have to undo and redo it, being careful to dismiss the suggestion box when it comes up. The suggestion boxes come up so frequently that I'm constantly banging on the escape key just to be able to type code. Worse, the suggestion boxes often obscures code that I'm looking at as a reference for the code I'm writing.

Turning off "auto list members" seems to help. I'd always looked at that setting and since I didn't know it was responsible for intellisense suggestion boxes, I never turned it off.

I've watched people who rely heavily on intellisense and I've noticed that they produce correct code slower than I do in the editor. They are going only as fast as their eyeballs can browse intellisense. I started coding before intellisense and IDEs and when I'm typing code, my fingers are way behind where my brain is dictating source code. Having the intellisense constantly popping up slows my fingers down even more and is quite annoying, since my fingers are already behind where my brain is dictating in the code stream.
accord Posted - Oct 05 2009 : 4:18:47 PM
I wasn't aware of this option, but it definitely disabled automatic member listboxes for me in VS2008 (but appears on ctrl+space)
feline Posted - Oct 05 2009 : 07:46:44 AM
Without knowing exactly when / why these listboxes are turning up I am not sure what is triggering them, but try turning off:

IDE tools menu -> Options -> Text Editor -> C/C++ -> Auto list members

this setting is in VS2005. If you are using VC6 then the setting is:

VA Options -> Advanced -> C/C++ 6.0 -> Auto list members
accord Posted - Oct 04 2009 : 12:49:23 PM
The remaining ones are "just" member listboxes which appear after typing a dot or -> and list the class members.

What is the most annoying in these boxes for you? The possibility to accidentally accepting a selection in the listbox or you just don't like the presence/pop up of any listbox/window in your work area at all? So it is "just" a visual annoyance?

We have options to greatly reduce the possibility of accepting wrong options accidentally so when you just type your text will never be overwritten by something else, but as far as I know we don't have any option to prevent all listboxes (including the ones pop up by intellisense).
legalize Posted - Oct 04 2009 : 11:38:48 AM
Yes, I've already done those two, but those boxes still flash up with way too much frequency. I keep asking the VS team for something that will disable all intellisense prompting until a keystroke is pressed and their response is something along the lines of "we'll get to it in 2015".
accord Posted - Oct 04 2009 : 05:46:50 AM
You can turn off all suggestions by

VA Options -> Advanced -> Suggestions -> Include suggestions in listboxes

Also, you may consider turning off

VA Options -> Advanced -> Suggestions -> Include VA Snippets in listboxes

as well, since they pop up when you type, like suggestions.

After that, when you press ctrl+space, you will get the suggestion. For example I created an int with the above settings are turned off, typed part of the variable, pressed ctrl+spce and the result:



Is this what you mean?
legalize Posted - Oct 03 2009 : 4:32:32 PM
If I had to choose between a more reliable and more widely applicable Rename and Inline Method, I would take the Rename.

All the list box prompting stuff that comes with VAX is something that I mostly disable. I know what code I want to write and the constant flashing up of suggestions is a distracting annoyance more than it is helpful. In that area, what I mostly want is a way to turn off all suggestion boxes until I type a keystroke requesting them.
feline Posted - Oct 03 2009 : 1:30:21 PM
First a general comment on all of this. I see a lot of feature requests, both here and via email, and have been doing so for a while now [:) If we tried to add even 10% of all the feature requests received then VA could easily get bogged down in a sea of features and options, making using it quite complex and confusing to use.

Secondly, often people will make a good case for their favourite new feature or option, but we have to ask how many of our users would benefit from this new item.

Thirdly, since we are selling VA we need to improve it, add value, which often means adding new features while also improving existing features. Balancing all of this is not always easy

It is really nice to see that overall people are very happy with our performance and easy of use

Now inverse refactoring, "inline method" is an idea that very rarely comes up. So far there does not seem to be a lot of demand for it, the same with Move Implementation to Header File. In contrast we get a lot of requests to apply Move Implementation to Source File to several methods all at once / in one go.

I am not "defending" the lack of the features here, I am just trying to give my perspective from a support point of view.

I have put a note about this discussion onto the feature request for Insert Method, the inverse of Extract Method:

case=1493

since this is a good explanation of why you want to do this.

We are also considering adding the command Move Implementation to Header File

case=10239

but as for doing this to inline functions, I recall seeing this discussed, and from memory the inline keyword is just a guide to the compiler, it will still make its own decisions.
membry Posted - Oct 02 2009 : 9:37:37 PM
Back again. To touch on a number of points from a number of posters.

* Understood that VAX is a productivity tool first and a refactoring too second. I use VAX everyday and find it indispensable. But VAX does offer refactoring - even if limited - and there is room for improvement. But if I find myself doing something over and over when working on legacy C++ code, and it seems to be a "small" refactoring, it would be nice if VAX could do it automatically instead of having to do it manually. Only, with C++, simple is rarely so simple.

* Regarding converting conditional statements and switch statements and vice versa, I should have added ternary statements to the mix. It's all about refactoring code to more clearly express intent. Long if-then-else chains can be more confusing than a switch statement. Short switch statements can be less clear than short if statements. And sometimes, such as constants and parameters (think MFC), a ternary is the best tool for the job. I actually use these refactorings in Refactor Pro!, when the performance issues are bearable. Having said that, I would agree with Legalize that Inline Method and other refactorings should be a higher priority for VAX. I suggested it because I do use them a lot when working on legacy code and they seemed to be small enough to be a good fit for VAX.

* I do use source control and it does give me the ability to revert refactorings in the short term. But months or even years down the road, having the ability to revert or change refactorings using inverses would be preferable.
legalize Posted - Oct 02 2009 : 4:48:06 PM
I definately agree that Extract Method and Move Implementation to Source need inverses. (I thought there was move implementation to header?)

Refactor! does have a large laundry list of refactorings and on the surface wins the "checklist debate". However, it slows VS.NET down to a crawl when you actually try to use it. I'd rather have a few refactorings that work reliably and quickly than a laundry list of slow buggy refactorings.

Several of my coworkers tried the free edition of Refactor! and they all uninstalled it. (I had a full license and I eventually uninstalled it as well.) However, once they all tried the 30-day trial of VAX they couldn't live without it and we all got a license.

I think that speaks for itself.

I think all would agree that C++ has some tricky syntax and that can throw a real monkey wrench at a seemingly simple refactoring like Rename. I'd rather that Rename worked on any identifier without error before seeing less useful refactorings like convert switch to conditional added to the product.

I haven't done an exhaustive check on VAX's rename, but you should be able to rename any identifier and have it adjusted in context. Think of all the places where identifiers appear in C++ and you'll realize the scope of this request: template arguments, macro arguments, macro names, typedef names, class/union/struct names, namespace names, enum names, variable names, method names, function names, etc. The kinds and scopes of identifiers in C++ are quite numerous. I'd rather have a Rename refactoring that just handled all these cases flawlessly before I'd need convert switch to conditional.

Of course, there are crufy code bases where convert conditional to switch would be handy. Its code written by novice C++/C programmers that looks like this:

if (arg == 1) { ... }
else if (arg == 2) { ... }
else if (arg == 3) { ... }
else { ... }

Its ugly and I've seen it before, but I can handle that one manually when I encounter it. Its far more often that I need a robust Rename when I'm working on code.

Rename. Extract Method. Extract Interface.

These are my day-to-day tools. I less often need the inverse of Extract Method. (And conceivably you could create an inverse for Extract Interface, but so far I've never needed that one.)

The easiest way to "undo" a refactoring is to make sure that you don't start doing refactorings until you've committed your code. Then you can use source control to undo errant changes that didn't work out as you originally hoped/planned. I've done this on more than one occasion. I like to keep my refactoring changes separate from changes designed to implement functionality.
membry Posted - Oct 02 2009 : 4:07:24 PM
Legalize really should be the one to discuss the need for inverse refactorings. He is the real domain expert when it comes to refactoring. He discusses the need for "Inline Method", the inverse of "Extract Method" in this topic at http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=8913. And yes, not having an inverse for "Extract Method" is the main one of missing links that I was referring to.

Going back to my analogy of refactorings as tools in a toolbox, not having an inverse of a refactoring is akin to having a "dull" tool instead of "sharp" tool. It automatically limits the usefulness and utility of said tool. Which is contrary to the UNIX philosophy of small and sharp tools. Even if an inverse is used only 10% of the time, it is still needed. In large part because large refactorings are often broken down into consecutive smaller refactorings, some of which are inverses of typical refactorings. Sometimes you have to take a step backwards in order to take two steps forward. But also because one of the underpinnings of refactoring and Agile is the ability to change your mind as circumstances and your understanding of the codebase change. With one-way automated refactorings, the ability to try something and then change it back, for whatever reason, becomes problematic because the inverse has to be done manually.

I wish I had some examples handy, but I have often used extract and inline refactorings (usually temporaries) as part of refactoring a few dozen lines down to a much smaller and more understandable number of lines. I would use "Inline Method" along with "Extract Method" if VAX had both. But it does not.

Another explanation of the need for an inverse of "Extract Method". From Fowler's canonical book on refactoring. I suspect.
quote:
The key refactoring is Extract Method, which takes a clump of code and turns it into its own method. Inline Method is essentially the opposite. You take a method call and replace it with the body of the code. I need Inline Method when IG??ve done multiple extractions and realize some of the resulting methods are no longer pulling their weight or if I need to reorganize the way IG??ve broken down methods.
http://sourcemaking.com/refactoring/composing-methods

Elsewhere on that site, it mentions, that before extracting a large class/object/method, it's often best to inline everything first then extract.

Out of time for now. Will try to respond to the rest in a separate post.


accord Posted - Sep 25 2009 : 5:13:00 PM
membry: I had felt like you: I wanted more and more refactoring, but then realized that I got features that save my time as well, and the final goal it to save time, and refactoring is "only" one of the tools which help achieve this. Nonetheless, more refactoring is always a good thing and I'm very happy with the two new refactorings: add include and create from usage. And feline is right: scoped suggestions are also very nice, I like them.

Anyway, do you miss an invert refactoring very much, which you would use often?
feline Posted - Sep 25 2009 : 3:34:41 PM
If you look at the changes over time in VA we put a lot of time and energy into improving and fixing bugs in our existing features, refactoring included. There are all sorts of edge cases that have tripped up our current refactoring commands.

If we simply add more refactoring commands without improving the quality of the existing commands this is not going to help much.

For the inverse refactoring, it depends which commands you are talking about. On a quick scan over our refactoring commands the only commands that I can really see a need to invert are:

Extract Method
Move Implementation to Source File

and personally I feel that the inverse of these commands is only going to be useful very occasionally.

Converting a switch to an if statement and back again, my honest reaction is why? If I have an if, elseif, else statement then normally you could never convert it successfully to a switch statement, since it is often done with logical comparisons, not a simple "A == B" check at every single point. Off the top of my head I don't think this has ever been requested.

Remember you cannot switch on strings in C++, which is one place where this might be useful.

A commonly requested option is to run a refactoring, e.g. Encapsulate Field on several items at once, which we are looking to do, and which should be quite helpful to a lot of people on a regular basis.

Look beyond refactoring though and look at the new scoped suggestions in the latest build. These are a real help once you get used to them.
membry Posted - Sep 24 2009 : 3:40:56 PM
You are correct. Not so simple after all. C++. Sigh.

Don't get me wrong. VAX still wins the C++ refactoring shootout. So far. In fact, the initial release was fantastic and I use VAX refactoring each and every day. But progress seems to have slowed quite significantly since then. I sort of hoped for a new refactoring or two every release and the pace does not seem it has been near that level. Surprising. Especially given the emphasis on short, simple and fast refactorings. Which I understand and support. It's the UNIX philosophy. Use a toolkit of sharp, focused. well-built tools then use a combination of those tools to do more complicated jobs. However, it does seem odd that of the supported refactorings some of the inverses are not also supported. And that some simpler refactorings offered by the competition such as conditional-to-switch and switch-to-conditional don't even seem to be on the radar screen for VAX. Hence my comment.
feline Posted - Sep 24 2009 : 1:19:13 PM
Starting on the 2nd or 3rd word is not going to work very well, since some types need several words and other types only need a single word, consider:

int nOne,
long long nTwo,
std::pair < std::string, std::string > mapThree


I often find that "simple" features and ideas are not that simple at all when you think about them in C++

Out of interest what do you mean about refactoring being a low priority? We put a lot of time and effort into our refactoring commands, so I am wondering what gives you this impression. We don't have hundreds of commands, preferring to have a small number of commands that can be chained together to achieve the desired result.
membry Posted - Sep 22 2009 : 11:24:24 PM
Thanks but I later thought of several examples where sorting on the last word wouldn't work such as declarations of const methods. So this won't work so well. Starting sort at 2nd or 3rd word instead of 1st word would probably be better.

You can cancel this request. I've been re-evaluating the competition's software (we do own a license) and CR_SortLines. The performance issues are getting better and i think I can use it in short doses and there are other reasons to use it even in small doses. Vastly prefer VAX but refactoring seems to be a low priority for VAX. :( Also never expected eXcel or full regex sorts but never thought it would be so hard to come up with a simpler alternative.
feline Posted - Sep 17 2009 : 3:14:54 PM
In the short term have you considered using an IDE macro to sort the lines? You could get it to sort out the comma's at the end of the lines as well, making sure that every line except the last one ended with a comma. This IDE macro should give you some ideas if you are interested in trying this:

http://support.wholetomato.com?W445

I have also put in a feature request for a command to sort lines by the last word, but I am not sure if this will ever actually be done:

case=32391
membry Posted - Sep 17 2009 : 12:11:49 AM
With regards to your breakage example, even the current "Sort Selected Lines" would break that. Use with caution and all that. Since I'm working on a legacy app which has functions with 20+ parms, I would rearrange your example to:

void simpleFunction(
int nParam3,
int nParam2,
int nParam1
);

and sort the parms and manually adjust the commas on two of the lines. That's what I currently do with VAX "Sort Selected Lines". I'm just asking for a sort that ignores the type in the above example. With the intent to refactor away a lot of the mess. Eventually. But in the meantime, classes with 100+ methods and/or 100+ members are easier to grok when long lists are in alphabetical order. Fortunately another tool puts each parm on a separate line for me. Sorting helps but must be used with caution. Even with the sorting that currently exists.

Just like regexes, we can make sorts as complicated as we might desire. Especially when you try to make sorts context sensitive. Easily too complicated. On that we can both agree.

Allow me to restate my original request. "Sort Selected Lines" can be thought of as a simple text sort of the first word of a line with successive words and grammar serving as tiebreakers. With that in mind, a text sort of the last word only (no tiebreakers) would be very helpful to me and hopefully not too complicated.

feline Posted - Sep 16 2009 : 08:24:47 AM
I also come from a UNIX background, but after jumping between Vim where I used some quite complex regex's, grep, egrep and vi, and also some windows programs multiple regex's used to make my head ache, since you could spend ages trying to figure out how to escape / and \\ for different programs, since I often needed to use these characters.

Personally I would not want to try and write a regex to pick out the variable from a declaration line, since I am all to aware of edge cases.

Your idea for sorting makes sense, but it relies on several assumptions. The obvious ones are that all the lines being sorted are declarations of variables / parameters. It also requires one variable per line. Often this is not going to be the case.

So you would need two sort commands. One to sort "normal" text, e.g. #include lines, and one to sort variables. Then of course you need to make sure you never select to much text when sorting variables, since any non variable line will confuse the issue.

The more I think about this, the less this sounds like "sort this block of text" and the more it sounds like some form of "complex" refactoring command. Sorting parameters is a good example, consider:

void simpleFunction(int nParam3,
  int nParam2,
  int nParam1);

even a proper "variable aware" sorting function is going to break this, unless it also understands that the opening and closing brackets need to be left alone, and so does the function name. Plus you would really want it connected to Change Signature, since you are changing how the function has to be called.
membry Posted - Sep 15 2009 : 6:17:33 PM
VS2005 and VS2008. Not VC6. Was using UNIX then. But coming from a UNIX background, using different regexes has never seemed difficult to me. Ah, the days of awk and sed.... But overall, the simpler the regex, the better. If IDE regexes vary too much, pick a standard and use a simple subset. GNU grep or whatever suits your tastes.

Again, "simple" sorting ignores all types and qualifiers. Sort the identifiers and only the identifiers. Those are a lot less complex. Besides, the current Sort Lines already sorts the qualifiers.

The proposed refactoring sounds like a step in the right direction but it probably should be bidirectional to be most useful. That is, allow the user to put the ctor init list in the same order as the decls -or- put the decl list in the same order as the init list. That folks like me could sort the ctor list and the have VAX sort the decl list from there.

But a more flexible VAX sort would still be very useful for things like param lists, etc.
feline Posted - Sep 15 2009 : 6:02:15 PM
Have you ever used the regex's for the IDE's Find and replace dialog? They are different in VC6 vs VS2005. A simple example, :i* behaves quite differently in the two IDE's. I like regex's, but I rarely bother with the IDE's Find and replace regex language since it is quite different to the other regex languages I use.

In this particular example I think sorting the lines is actually the wrong approach. Any "simple" sorting rule is going to fail here. What about const and pointers? More complex template types? You need something that really understands the code as code.

We are considering a refactoring command to sort the constructor's initialization list into the order the members are declared in the class:

case=8368
membry Posted - Sep 15 2009 : 3:13:46 PM
Understand about the confusing diversity of regexes in the wild. But in this case, VAX runs inside the VS IDE. Just support the same regexes as the VS Find and Replace toolbox and be done with it. Might even be able to get VS to do some of the regex heavy lifting for VAX.

As requested, an example from said legacy code:

Desired sort order in ctor init list:

CMailMessage::CMailMessage()
: m_Body("")
, m_DateTime()
, m_From("")
, m_Header("")
, m_MIME(e_MIME_NONE)
, m_MIMEString("")
, m_MessageID("")
, m_Recipients()
, m_Status("")
, m_Subject("")
{
}

VAX sort order from member declaration list:

class CMailMessage
{

...

private: // Member data.

CTime m_DateTime;
e_MIME m_MIME;
std::string m_Body;
std::string m_From;
std::string m_Header;
std::string m_MIMEString;
std::string m_MessageID;
std::string m_Status;
std::string m_Subject;
std::vector<std::string> m_Recipients;
};

The sort orders are different because the entire line is sorted not just the second "column". In this example, initializing members in a different order than they are declared can lead to inconsistent state.

What would be helpful is a sort where VAX would ignore all qualifiers such as punctuation, types, etc. Or to keep things simpler, VAX could pretend the 2nd or 3rd tokens were "columns" and sort on that.

feline Posted - Sep 15 2009 : 1:28:56 PM
I am a great fan of regular expressions, but they have one major problem. Every program that I use that supports them does so differently *sigh* So most people never make much use of them in reality, since it is to hard to work out how to make them do really interesting things.

Can you post a short code example to explain what you are trying to achieve? What do you mean by the 2nd or 3rd columns? This literal column in the editor or something slightly more abstract?
membry Posted - Sep 14 2009 : 1:18:21 PM
Cutting and pasting is one thing that I would prefer to avoid. Have to deal with too much of it already in the legacy code base....

Not suggesting that you make it complicated. Although, if a parse tree already exists for other reasons, is it that complicated to sort on names only? Even just the ability to sort on 2nd or 3rd columns would be a significant help.

Alternatively, allow a user-specified regex. Check out CR_SortLines at http://code.google.com/p/dxcorecommunityplugins/wiki/CR_SortLines for an example. It uses the competition's software. If the competition's engine wasn't such a performance hog and the sorts weren't always case insensitive, I'd use this AddIn.

feline Posted - Sep 14 2009 : 10:30:19 AM
I see the appeal, but I am bothered by how complex this could be to do properly. You might need a rather complex dialog box, listing various rules for breaking up the words, and how you are going to group and sort them...

In a situation like this I would actually be tempted to copy / paste the lines into another program and group / sort them there.

On a command line I would use a bit of grep to pull out the "get..." lines and sort them to one file. Do the same for the "set..." lines into another file, and merge the files together. Quite quick and easy if you are familiar with the command line programs, but I am not sure how I would do this in an editor.

A regular expression find and replace should let you "delete" all the lines you don't want, leaving you with one group, which could then be sorted.

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