Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Default 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 at 11:02 AM. Reason: Grammar fix

  2. #2
    Join Date
    Oct 2007
    Location
    Pennsylvania
    Posts
    1,772

    Default

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

  3. #3
    Join Date
    Nov 2008
    Posts
    3

    Default

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

  4. #4
    Join Date
    Oct 2007
    Location
    Pennsylvania
    Posts
    1,772

    Default

    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
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

  5. #5
    Join Date
    Nov 2008
    Posts
    3

    Default

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

    Thanks!

  6. #6
    Join Date
    Oct 2007
    Location
    Madison, WI
    Posts
    11,788

    Default

    Thanks, Michael.
    Aaron P Scooter Software

  7. #7
    Join Date
    Oct 2007
    Posts
    786

    Default

    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

  8. #8
    Join Date
    Oct 2007
    Posts
    786

    Default

    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

  9. #9
    Join Date
    Aug 2007
    Location
    Minnesota
    Posts
    2

    Question Smart brace matching in C-derived languages

    Fifteen months have passed since you wrote this:
    Quote 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.

  10. #10
    Join Date
    Oct 2007
    Location
    Madison, WI
    Posts
    4,677

    Default

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •