View Full Version : Brace matching in C#
fatcat1111
13-Nov-2008, 12:44 PM
Hello, I am seeing some odd behavior when diffing two C# source files where one has a new method. Attached is what BC3 shows as the diff. Rather than show the old methods ("1" and "3") as unchanged and just the new block ("2") as added, it shows 1's closing brace as deleted, and 2's new closing brace as unchanged.
Is there a setting I can use to fix this?
Michael Bulgrien
14-Nov-2008, 11:05 AM
What build of BC3 are you running? It works correctly for me on v3.0.10.9357.
fatcat1111
14-Nov-2008, 11:22 AM
Hello, I am running version 3.0.10 build 9357. This is a fresh install, using the defaults.
Michael Bulgrien
14-Nov-2008, 11:38 AM
Have you tried turning on visible whitespace? I can duplicate your situation if I change the leading whitespace as illustrated in this screenshot (http://screencast.com/t/ObLAmyJn6dc). As long as the leading whitespace is consistent, the methods align as expected.
fatcat1111
14-Nov-2008, 12:07 PM
Ah, that was the problem. One had an additional space :P
Thanks!
Aaron
14-Nov-2008, 04:04 PM
Thanks, Michael. :)
I'm glad your specific issue was resolved, but we should mention that BC will not always do what you expect in cases like this. The alignment algorithm is line-by-line and does not recognize the scope of methods or paired braces.
For example, I took your snippet and added a bunch of matching text after the insertion, and a difference just before the insertion. Notice how the larger block of matching text tends to maximize its extent, grabbing matching lines upwards.
In my case, switching to the "alternate" alignment algorithm made no difference.
There's not much we can do about this right now. I've considered changing our algorithm to give priority to downward matching over upward matching but I'm not sure that will be an improvement in all cases. The best solution of course would be an alignment algorithm that understood the scope of procedures, but we won't be looking at that anytime soon.
RichA
17-Feb-2010, 11:57 AM
Fifteen months have passed since you wrote this:
... The best solution of course would be an alignment algorithm that understood the scope of procedures, but we won't be looking at that anytime soon.
So I thought I'd ask: By any chance is Scooter working on an algorithm for C(-like) code that could treat code-block brace placement as unimportant. For example, a change consisting solely of moving an opening brace to or from a line of its own would be considered unimportant.
My apologies if I'm the zillionth person to raise this issue, but if such a feature were in BC, I'd spend all the time it would save me trying to find a suitable expression of my gratitude -- probably without success.
Chris
18-Feb-2010, 06:04 PM
Hi RichA,
Sorry, we aren't working on a new algorithm right now. It is still something we'd like to support in some future release.
vBulletin® v3.7.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.