Fog Creek Software
Discussion Board




Language-aware diff tools?

Are you aware of any GUI diff tools that are smart enough to consider syntactical features of the language when determining differences?  Something that can recognize that a call to a many-parameter method with one parameter on each line is the same as when all parameters were stretched across one long line?  Something that would ignore comments if you asked it to?  Something that would be case-insensitive for keywords and identifiers (if you were using a case-insensitive language), but maintained case-sensitivity for string literals?

It gets very frustrating sometimes when a whole bunch of differences get highlighted just because you or somebody else ran the code through a formatting tool.

T. Norman
Wednesday, June 23, 2004

That would be an extremely specialized tool to have.  Even the best diff program I've seen so far (ExamDiff Pro), uses a simple technique at it's core. (The guy at PrestoSoft is someone who can build an app "Soup to Nuts".)

I feel your pain dude.

Wayne
Wednesday, June 23, 2004

I think that Beyond Compare will do some of what you're looking for (but probably not all).  Nevertheless, it's an awesome product, has configurable language support, and is well worth a download to try it out.

See http://www.scootersoftware.com

John Rusk
Wednesday, June 23, 2004

Beyond Compare (www.scootersoftware.com) has some of these abilities. Ignoring comments at least. Not sure about anything else.

(I am not associated with them, etc...)

sgf
Wednesday, June 23, 2004

Agh, John types faster...

sgf
Wednesday, June 23, 2004

OMFG, where are the "nice advertisement" trolls at?

Anon
Wednesday, June 23, 2004

I don't know of any tools that perform such a function. However I don't see many problems writing a tool to do this. First determine what language the file is and run it through a yacc or javacc based parser for that language. Then compare the parse tree.

There are XML diff tools available which perform a similar function, using DOM.

Rhys Keepence
Wednesday, June 23, 2004

Run, don't walk to Beyond Compare. It's the best diff program I ever saw.

Matthew Lock
Wednesday, June 23, 2004

'diff -uw' does whitespace-insensitive comparisons in a nice format.

Phillip J. Eby
Thursday, June 24, 2004

T. Norman, what you need is something that makes comparison between Abstract Syntax Tress, not text files. You may try an IDE with refactoring capabilities - many of them have a "Rewrite engine" that allows you to create, compare and manipulate AST as you like.

Giovanni Corriga
Thursday, June 24, 2004

I don't need something that incredibly intelligent... basically, just something that knows how to ignore comments, case, and can recognize that

if (x) {
doSomething(a,b,c,d);
}

is the same as

if (x)
{
  do Something(a,
                b,
                c,
                d);
}

For that, just basic rules about the language are required, not the entire grammar.

Hmmm... maybe I should write one and sell it!

T. Norman
Thursday, June 24, 2004

On my Linux machine,  here's what I do:

$indent file1.c > file1.c.indented
$indent file2.c > file2.c.indented
$xxdiff file1.c.indented file2.c.indented

easily can be canned into a script for frequent use.

("indent" is a command-line filter utility for autoformatting (very customizable).  xxdiff is a graphic difference tool)

Kobi
Thursday, June 24, 2004

What Giovanni said. Essentially any refactoring tool has to be able to do this, so why not look at some of them? Eclipse has it and it is open source, so in principle you could cadge the source you need and wrap it into your own tool for your own use.


Thursday, June 24, 2004

Eclipse has refactoring options but the diff capability apparently is text-based. Do you know how can I make a language-aware diff inside Eclipse?

R
Thursday, June 24, 2004

BeyondCompare can do all the things you listed. It can ignore comments, upper/lower case, strings, etc.

~ ~ daveg

DaveG
Thursday, June 24, 2004

> It gets very frustrating sometimes when a whole bunch of differences get highlighted just because you or somebody else ran the code through a formatting tool.

Can you have your own formatting tool, and run files through it before you subject them to a diff (so that the diff is on standardly-formatted files)?

Christopher Wells
Thursday, June 24, 2004

Just like Kobi said.....

Ian H.
Thursday, June 24, 2004

BeyondCompare give me three extra inches!

V1agr@!
Thursday, June 24, 2004

Beyond Compare certainly understands C++.  I think it uses a relatively simplistic algorithm for deciding which parts match which other parts, and sometimes doesn't quite see which two lines are really supposed to line up.  But it can tell comments from non comments, and understands that whitespace differences are unimportant  (though maybe not when it comes to newlines, can't remember).

You can write your own plugins for it too, which is cool.  I want to write one that compares resources and entry points on dlls, but haven't really gotten started on that one.

Keith Wright
Thursday, June 24, 2004

*  Recent Topics

*  Fog Creek Home