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
 Technical Support
 1623: "Move Implementation" removing whitespace!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 06 2007 :  3:39:16 PM  Show Profile  Reply with Quote
IDE: Visual Studio 2008

Hi,

Suppose the following C++ code in a header file:


class CMatrix3
{
	CVector operator*(const CVector &v) const
	{
		// 9 muls, 6 adds
		return CVector(	m[0][0]*v.x + m[1][0]*v.y + m[2][0]*v.z,
				m[0][1]*v.x + m[1][1]*v.y + m[2][1]*v.z,
				m[0][2]*v.x + m[1][2]*v.y + m[2][2]*v.z);
	}
};


If I "Move Implementation to Source" on the multiplication operator above, the C++ output in the CPP file appears as follows:


CVector CMatrix3::operator*( const CVector &v ) const
{
	// 9 muls, 6 adds
	return CVector(	m[0][0]*v.x + m[1][0]*v.y + m[2][0]*v.z,
		m[0][1]*v.x + m[1][1]*v.y + m[2][1]*v.z,
		m[0][2]*v.x + m[1][2]*v.y + m[2][2]*v.z);
}


As you can see, some tabs were removed.

In addition, spaces were added in the parameter list after the opening parenthesis and before the closing parenthesis when there were none to begin with in the prototype (as you can see from the first code snippet).

Expected behavior:
In both cases, VAX should retain all white space with the exception of whitespace required to be removed in order to shift the entire code block to make it match the new scope.

Edited by - MrDoomMaster on Dec 06 2007 3:40:03 PM

rhummer
Tomato Guru

USA
527 Posts

Posted - Dec 06 2007 :  3:47:57 PM  Show Profile  Reply with Quote
Move Implementation uses the VA Snippet entry "Refactor Create Implementation" Tweak that entry to 'fix' the spaces in the parameter list.

Tools Engineer - Raven Software
VS2005 SP2/VS2008 SP1 - VAX <LATEST> - Win 7 x64


Edited by - rhummer on Dec 06 2007 3:48:11 PM
Go to Top of Page

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 06 2007 :  4:05:35 PM  Show Profile  Reply with Quote
quote:
Originally posted by rhummer

Move Implementation uses the VA Snippet entry "Refactor Create Implementation" Tweak that entry to 'fix' the spaces in the parameter list.



Could you provide some example VA snippet code for the "Refactor Create Implementation" item that would solve the parameter list spacing issue as well as the indentation being removed?
Go to Top of Page

rhummer
Tomato Guru

USA
527 Posts

Posted - Dec 06 2007 :  4:28:43 PM  Show Profile  Reply with Quote
Tweaking the VA Snippet only fixes the parameter list. All you have to do is tweak the formatting around the parentheses..

I assume the other issue is a bug, but I'll let feline answer that. :)

Tools Engineer - Raven Software
VS2005 SP2/VS2008 SP1 - VAX <LATEST> - Win 7 x64

Go to Top of Page

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 06 2007 :  4:33:52 PM  Show Profile  Reply with Quote
quote:
Originally posted by rhummer

Tweaking the VA Snippet only fixes the parameter list. All you have to do is tweak the formatting around the parentheses..

I assume the other issue is a bug, but I'll let feline answer that. :)



If I remove the spaces in the VA Snippet around the parenthesis, will create implementation still add spaces between them IF they existed in the prototype?

::EDIT::
I just tried it, it also won't ADD spaces within the parenthesis if the prototype had it, assuming that you've removed any whitespace in the snippet. It seems like $ParameterList$ should include trailing and leading whitespace.

Edited by - MrDoomMaster on Dec 06 2007 4:45:18 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  09:08:18 AM  Show Profile  Reply with Quote
The snippet "Refactor Create Implementation" is used for "Move Implementation to Source File", "Change Signature" and "Create Implementation"

While a prototype does exist for two of these, we cannot simply preserve the white space when running Change Signature. This is a known problem, but it is a hard problem to solve since it has so many edge cases.

So instead VA applies the white space given in the snippet for the start and end of the parameter list when running these commands, on the theory that consistency is good. I get the impression most of our users want all of their code formatted the same way, which the current system produces.

Also sometimes Move Implementation to Source File has to change the parameter list, default parameters are a good example of this, which further complicates matters.


Loosing the custom formatting inside the function body does look like a bug to me:

case=10385

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 07 2007 :  10:19:45 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

The snippet "Refactor Create Implementation" is used for "Move Implementation to Source File", "Change Signature" and "Create Implementation"

While a prototype does exist for two of these, we cannot simply preserve the white space when running Change Signature. This is a known problem, but it is a hard problem to solve since it has so many edge cases.

So instead VA applies the white space given in the snippet for the start and end of the parameter list when running these commands, on the theory that consistency is good. I get the impression most of our users want all of their code formatted the same way, which the current system produces.

Also sometimes Move Implementation to Source File has to change the parameter list, default parameters are a good example of this, which further complicates matters.


Loosing the custom formatting inside the function body does look like a bug to me:

case=10385



The fact that retaining spaces in the parameter list is so difficult seems like bad design to me. Regardless of how difficult it may be, if you completely rewrote that part of VAX and took a few days to think about a better way to implement that specific feature, I'm sure you could find a better solution.

In any case, the spaces not being retained in the parameter list is *also* a bug. The fact that it is hard to fix doesn't mean that it shouldn't be fixed, that's just one more great excuse to fix it. It'll probably force you to refactor your architecture too, since when problems get closer to "impossible" to fix that almost always means you need to refactor your design.

One thing that seems broken is that you're using the same VA snippet script for 3 *completely* different concepts. While I'm sure a majority of each of these concepts (Move Implementation, Change Signature, and Create Implementation) may seem similar and thus would be duplicated, the very fact that it makes fixing EXTREMELY simple bugs like whitespace issues difficult (and even more so, the fact that they exist) probably means you need to separate this into 3 snippets. I'd rather have to copy/paste my snippet 3 times and apply very minor differences to each of them then to have weird issues like this that I end up waiting over a year to get fixed (since that's usually the turnaround time for whitespace bugs around here).

The spaces in the parameter list normally isn't a problem if you're working with a consistent code base, as you stated. However in some cases that's not possible. For example, if you have 4 people on a project and there are no whitespace guidelines on the project, or if people simply refuse to abide by them, you end up being in situations where you have to refactor someone else's code. Right now if I want to move someone's implementations to the source file, I have to edit the Move Implementation VA snippet to match the whitespace of the parameter list so that the output generated by Move Implementation matches the prototype.

I don't mean to say "VA's code sucks" (even though that's what it may sound like). I couldn't possibly say that anyway since I haven't seen the code. I just know in my experience when simple issues are hard to fix, that usually means bad architecture. I'm simply concerned about the well-being of my most favorite refactoring/intellisense tool :) Perhaps the splitting of the VA snippet into 3 snippets would help mend the issue?

In any case, I hope you guys don't just ignore the parameter list whitespace issues. While I'm sure you believe whitespace issues deserve the lowest priority in your bug database, at least they will be in there.

Edited by - MrDoomMaster on Dec 07 2007 10:20:58 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  2:52:31 PM  Show Profile  Reply with Quote
I think we are talking about different things. The thing I am calling "hard to fix" is the white space *between* parameters, new lines, this sort of thing. It is quite easy to think up cases where it is rather hard to see what the code should do. This is not a question of "code is hard to write", it is instead a question of "what code do we want to write?"

Different files and parts of the project using different formatting styles, this is indeed a problem. We are considering some form of general solution to code formatting, but it is only a vague idea at this stage. It is a very large area to start getting into.

Taking your point one step further, I have seen and worked on code where one code formatting style is applied to the header file but a different code formatting style is applied to the matching cpp file *sigh*

I have unhappy memories of files where the code formatting style changed, at random, every few lines, even in the middle of functions. Once you get to this stage, which is where the situation describes can lead, any simple automated rule is useless.


Applying a single snippet to several different operations, you are quite right, you can make a good argument that this is a bad idea. However consider the opposite. Experience suggests most of our users don't want to edit snippets. Having to edit one snippet to fix formatting for several refactoring operations is much easier than having to format 3 different snippets.

It is a bad idea from some perspectives, and a better idea from other perspectives.


Moving from one area in a large project to another, where there are different code formatting "rules" is an interesting question that I discussed with another user recently via email, and some partial solutions came out of that discussion.

They wanted several "groups" of snippets, for different formatting purposes, and the ability to toggle between them. An interesting idea, and I do see the appeal, but I can also see various practical problems with implementing this, and how it "scales".

Let me go and write up the conclusions I reached from that as an FAQ entry a moment.

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 07 2007 :  3:01:51 PM  Show Profile  Reply with Quote
Just make $ParameterList$ include any trailing/leading spaces all the way up to the ( and ) characters and you've fixed the problem of spaces after/before the ( and ) symbols not being included. Is it really more difficult than that? What would that break?

I'm not sure what you're talking about when you mention whitespace between parameters. That seems to work fine right now. Are you talking about weird, cases, like this:

void foo(  int param1,
           int param2
           )
{
}


If so, you could also make this work if you made $ParameterList$ copy *all* whitespace. This means it would copy tabs, carriage returns, spaces, and other relevant white-space.

::EDIT::
I just tested, carriage returns between parameters are replaced with single spaces.

Edited by - MrDoomMaster on Dec 07 2007 3:07:34 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  3:18:05 PM  Show Profile  Reply with Quote
http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=7024

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

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  3:25:19 PM  Show Profile  Reply with Quote
I agree that having $ParameterList$ copy the leading and trailing white space is easy, but is this what we want? Look at your example, it has a leading space and a trailing EOL + some white space.

I am indeed talking about weird cases like that, but they quickly get "more" weird when you start thinking about it.

Copying all white space breaks down quite quickly as soon as you use Change Signature to change the number of parameters, or use Move Implementation to Source File or Create Implementation to create code in the cpp file. Consider this header file:

class CTestFormatting
{
    void parametersAreWrappedAndAllined(int nParam1,
                                        int nParam2,
                                        int nParam3);
};


That is fine, but when you get to the cpp file you suddenly have:

void CTestFormatting::parametersAreWrappedAndAllined(int nParam1,
                                    int nParam2,
                                    int nParam3)
{
}

which is "wrong" for certain values of right and wrong. I have already seen various discussions go by about how code like this "must" be formatted. Strangely enough different people have different opinions on it

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 07 2007 :  3:38:39 PM  Show Profile  Reply with Quote
I can see how automating this process can be so impossible. There's hundreds of different formatting possibilities and it's truly difficult to predict what the user will want. This is why I like your idea of multiple snippets for each type of operation, so depending on my mood or depending on who's code I'm refactoring, I could switch to the appropriate snippet and my Move Implementation will use the active snippet. Perhaps you guys could add a cool context menu that pops up when you use SHIFT+ALT+Mouse Wheel :)

In any case, you guys know this is an issue (which is good). Finding a solution, however, is quite a different story. I understand now what you were talking about.

Perhaps you could add a new snippet called "Predictive New Parameter" or something, that defines a Regex type of expression that can be used to format new variables into function headers. It would define whitespace & other things. However this may not even work, since from the script itself you'll never know how much to tab over (since you have no idea what scope you're in).

I'll leave the hard thinking up to you guys. I just wanted to make sure the issue was known. Whatever you guys come up with, though, I'm sure I'll like it.

Thanks for the input guys.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  3:48:30 PM  Show Profile  Reply with Quote
White space formatting, this is one of those things that sounds SO easy at first, and just gets worse and worse the more you think about it *sigh*

Swapping between Snippets via some form of menu, I like the idea, but working out how to have a "simple" menu / interface that would scale well was the problem. If you have any cunning idea's I am certainly happy to discuss them.

If you want to do "clever" changes, to update more than one Snippet at a time, then the VBScript I mention in the FAQ might be the best way forward. This way you get total control, and you can even ask the IDE nicely to bind it, complete with command line parameters, to a menu item or keyboard shortcut.

Otherwise I have this horrible vision of the "Snippet switcher" becoming an entire product in its own right

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

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 07 2007 :  3:49:40 PM  Show Profile  Reply with Quote
Oh yes, for reference, the bug about refactoring and white space *between* parameters is:

case=1631

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

schoenherr
Tomato Guru

Germany
160 Posts

Posted - Dec 10 2007 :  01:03:38 AM  Show Profile  Reply with Quote
@feline
regarding "swapping between snippets":
while your script tries to solve the problem in a general manner, i can imagine that most of the users would have a complete set of snippets which should be swapped. so what about to have two ore more copies of the file and simply overwrite the active file with the desired one?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 10 2007 :  09:27:29 AM  Show Profile  Reply with Quote
You can certainly do that, and quite a bit more easily. The problem with this approach is that you then need to keep all copies of the TPL files in sync, making any changes you want to other, more "stable" snippets in all files.

Using some form of script you can update several snippets in a single pass, with a single command line parameter. The script I posted was simply an interesting experiment, I wanted to see how well I could do something like that in VBScript I can see various ways to improve it, if I was using it heavily.

The different approaches have different benefits and drawbacks. It is just a case of finding the approach that suits you best.

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 10 2007 :  09:40:38 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

You can certainly do that, and quite a bit more easily. The problem with this approach is that you then need to keep all copies of the TPL files in sync, making any changes you want to other, more "stable" snippets in all files.

Using some form of script you can update several snippets in a single pass, with a single command line parameter. The script I posted was simply an interesting experiment, I wanted to see how well I could do something like that in VBScript I can see various ways to improve it, if I was using it heavily.

The different approaches have different benefits and drawbacks. It is just a case of finding the approach that suits you best.



I'd really hate to have to learn another language to use snippets. I'd rather VAX keep the C++-like syntax. VBScript would be terrible IMHO.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 10 2007 :  10:00:25 AM  Show Profile  Reply with Quote
I need to use VBScript to program and control our automated testing tool. As a language its not so terrible when you get past the screaming and the urge to throw things at the computer

A simple batch file to rename the TPL files might be the best solution, if you want to easily swap between files. This was my original suggestion to the other user, but they did not like having to keep the files in sync by hand. A diff program will do this just fine, but it is an extra step you need to take.

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Dec 10 2007 :  10:02:28 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

I need to use VBScript to program and control our automated testing tool. As a language its not so terrible when you get past the screaming and the urge to throw things at the computer

A simple batch file to rename the TPL files might be the best solution, if you want to easily swap between files. This was my original suggestion to the other user, but they did not like having to keep the files in sync by hand. A diff program will do this just fine, but it is an extra step you need to take.



Use Python :)
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 10 2007 :  11:32:15 AM  Show Profile  Reply with Quote
The testing tool only accepts certain scripting languages, and Python is not one of them

Going back to the point about batch files, I remembered the problem with this. When you have a group of 3 or 4 C++ TPL files that you are moving between it is quite easy to "loose" or "destroy" your recent changes to the snippets file by overwriting the file with one of the other reference files.

An easy solution, but not automatically a safe one.

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