tags:

views:

90

answers:

5

Are there any (ideally GUI) diff tools that are aware of syntax?

As an example of the kind of thing I'm looking for, I keep finding that my current tool miss aligns repetitive code:

Foo  = { 'hello': 'world',    |  Foo  = { 'hello': 'world',
         'goodnight': 'moon'  |           'goodnight': 'moon'  
       }                      <
                              <
Bar  = { 'picture': 1000,     <
       }                      |         }

I'd like a tool that would try and make matching braces on one side align with matching braces on the other.


Edit: I'm looking for a tool that can automatically spot that condition and correct it's alignment.

A: 

Beyond Compare will let you realign lines that it mismatches. I generally have good luck with it matching lines properly.

JYelton
I'm using BC and I'm looking for something automatic.
BCS
A: 

I think Beyond Compare has what you are looking for http://www.scootersoftware.com/index.php

Jake1164
I'm using BC and while it lets me fix the alignment by hand (not what I'm looking for), I don't know how to make it do it automatically.
BCS
+1  A: 

I like Source Gear's DiffMerge.

Nick
Agreed, I use this as well, it is a great tool.
Barlow Tucker
I don't see any indication in the docs of what I'm looking for. It can define matching elements but it doesn't seem to allow them to nest and it doesn't say that it uses them as alignment hints.
BCS
A: 

You can see all the posibilities and compare the features & prices. http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools

Jake1164
A: 

Not GUI based, but completely syntax driven: my company's Smart Differencer tools for many langauges (incluiding Java, C#, C++, PHP, Python, JavaScript, ...)

The Smart Differencer parses the source text like the compiler, so it understands that language syntax and structures the way the compiler does. It compares these structures (using ASTs) to determine the "least edit distance" in terms of edit actions (move, copy, delete, replace, rename-identifier-in-block) on these structures and report them.

In your example, it would know the curly brace on the right belongs to foo, not bar, and would tell you that the entire statement involving bar was simply deleted.

The output style is diff-like if you want to feed the result to another tool, or more human readable if you want to examine it directly.

Ira Baxter
Sounds really neat, but both over kill and not exactly in the right direction.
BCS
@BCS: Dunno about overkill. If you don't pick up the language structures, you can't match them; I don't know of any alternatives that can come close unless all you want is just bracket matching. What's not the right direction part?
Ira Baxter
@Ira: bracket matching and (similar alignment hinting rules) is all I want (I guess "syntax aware" is a little strong for what I'm looking for) and I'm wanting a text diff, just one that does a better job of figuring out what's new vs. old.
BCS
@BCS: I'm puzzled. If you *really* want better identification of new vs. old, you *really* want the syntax-driven comparison, because it provides descriptions in terms of what the programmers (reviewers?) understand. "You deleted the statement involving bar" seems pretty descriptive of the change you exhibited.
Ira Baxter
What I want is "Line 127 became line 134" in a reasonably language agnostic form. Given that it would be driving a GUI, not dumping text, anything else would need to be munged into that anyway with all the disambiguations heuristics that requires.
BCS
@BCS: Go check the examples provided at the website. For a move, it produces diffs with detail line and column information L:C which I'll designate P,Q,R,S here. For a delete, it says range P-Q is deleted; for a move you get "Moved range P-Q to range R-S". You can ignore the column data if you want, etc. There's an output that can drive a GUI; see the COBOL GUI example for SmartDifferencer.
Ira Baxter
The problem is, I already have something (Beyond Compare) close to what I want but it's missing something. While the program you mention seems to be able to do that something, it's also missing a few things (GUI, etc.) that I want and (and this is a significant point) it has a bunch of things I don't care about. I might live with some lacks or excesses but not both.
BCS