tags:

views:

78

answers:

1

diff usually produces rather clueless output. Here's a good example. If we start with this:

class World
  def hello
    puts "Hello, world"
  end
  def goodbye
    puts "Goodbye, world"
  end
end

Drop the second method and change the first:

class World
  def hello
    puts "Hello, #{self}"
  end
end

diff -u will be a total mess - suggesting two methods have been merged:

 class World
   def hello
-    puts "Hello, world"
-  end
-  def goodbye
-    puts "Goodbye, world"
+    puts "Hello, #{self}"
   end
 end

Instead of much more reasonable:

 class World
   def hello
-    puts "Hello, world"
+    puts "Hello, #{self}"
   end
-  def goodbye
-    puts "Goodbye, world"
-  end
 end

This is just a toy example, so diff's output is still possible to understand - in practice it usually gets a lot worse.

Are there any alternatives to diff that might be somewhat smarter?

+1  A: 

You might consider our SD Smart Differencer. It provides differences based on the structure of the code rather than "line differences", so it is focused on language elements (expressions, statements, blocks, methods) and editing actions (delete, insert, copy, replace, rename).

It is language specific; it has to be to use language structure as a guide. It uses an explicit langauge definition. I can't quite tell what langauge you are using (Python?). There are Smart Differencer tools for many langauges, including C, C++, C#, Java, Python, Fortran, COBOL, ...

Ira Baxter
The example is in Ruby. Smart Differencer looks like it's Windows-only, without support for most languages I want (and what they say about C preprocessor implies it won't even be able to diff most C), closed source (very bad idea for development tools), and I'm not even sure if a trial download to see if it works at all is available. Perhaps some other people will find it useful.
taw
What languages did you want? Yes, there are limitations with C code due to the arbitrary placement of preprocessor directives and macro calls; these make it very hard to identify code structure in arbitrary C code. It doesn't presently work with Ruby; we've played with a Ruby language definition but it isnt ready yet.. Yes, it is closed source; you are welcome to write an open source version. You didn't state any of these as constraints in your question. There are evaluation versions available for a wide variety of languages, including Java, C# and C++. You might have to ask at the website
Ira Baxter