Announcement

Collapse
No announcement yet.

Brace matching in C#

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Brace matching in C#

    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?
    Last edited by fatcat1111; 14-Nov-2008, 12:02 PM. Reason: Grammar fix

  • #2
    What build of BC3 are you running? It works correctly for me on v3.0.10.9357.
    BC v4.0.7 build 19761
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

    Comment


    • #3
      Hello, I am running version 3.0.10 build 9357. This is a fresh install, using the defaults.

      Comment


      • #4
        Have you tried turning on visible whitespace? I can duplicate your situation if I change the leading whitespace as illustrated in this screenshot. As long as the leading whitespace is consistent, the methods align as expected.
        BC v4.0.7 build 19761
        ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

        Comment


        • #5
          Ah, that was the problem. One had an additional space :P

          Thanks!

          Comment


          • #6
            Thanks, Michael.
            Aaron P Scooter Software

            Comment


            • #7
              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.
              Tim T Scooter Software

              Comment


              • #8
                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.
                Tim T Scooter Software

                Comment


                • #9
                  Smart brace matching in C-derived languages

                  Fifteen months have passed since you wrote this:
                  Originally posted by Tim View Post
                  ... 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.

                  Comment


                  • #10
                    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.
                    Chris K Scooter Software

                    Comment


                    • #11
                      Brace detection

                      Chris, I wanted to confirm, is this what you are discussing?
                      Click image for larger version

Name:	nhPAMNC.png
Views:	1
Size:	102.0 KB
ID:	76292

                      I assume there is no way to configure this with Beyond Compare?
                      I am looking at a copy of Pixi.js compared against a local copy and struggling to see if there are custom changes in my project, because the alignment of braces is all different

                      Comment


                      • #12
                        Using different alignment settings and line weights can help. We added a new Alignment type specifically to help with this case in BC4 in the Text Compare's Session Settings -> Alignment tab: Patience Diff.

                        You can install the trial of BC4 without removing or altering BC3. This way you can test to be sure it meets your needs with your files before purchase is necessary:
                        http://www.scootersoftware.com/download.php
                        Aaron P Scooter Software

                        Comment

                        Working...
                        X