Brace matching in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fatcat1111
    Visitor
    • Nov 2008
    • 3

    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
  • Michael Bulgrien
    Carpal Tunnel
    • Oct 2007
    • 1772

    #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

    • fatcat1111
      Visitor
      • Nov 2008
      • 3

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

      Comment

      • Michael Bulgrien
        Carpal Tunnel
        • Oct 2007
        • 1772

        #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

        • fatcat1111
          Visitor
          • Nov 2008
          • 3

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

          Thanks!

          Comment

          • Aaron
            Team Scooter
            • Oct 2007
            • 15945

            #6
            Thanks, Michael.
            Aaron P Scooter Software

            Comment

            • Tim
              Team Scooter
              • Oct 2007
              • 786

              #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

              • Tim
                Team Scooter
                • Oct 2007
                • 786

                #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

                • RichA
                  New User
                  • Aug 2007
                  • 2

                  #9
                  Smart brace matching in C-derived languages

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

                  • Chris
                    Team Scooter
                    • Oct 2007
                    • 5533

                    #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

                    • sa4151
                      New User
                      • Oct 2014
                      • 1

                      #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

                      • Aaron
                        Team Scooter
                        • Oct 2007
                        • 15945

                        #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...