I am dissatisfied with the file comparison tools I have worked with so far. While no tool would be able to always predict the line matchings that make best sense, at least current tools should be able to do a better job when changes mostly consist of added and removed indentation. But the tools have I used end up matching braces in isolation and separating actually related code, and do other seemingly obvious mistakes.
An example will speak volumes, let us take this:
// We also have to add any specified prefix and (pre-period) suffix.
if (prefix) [spriteName insertString:prefix atIndex:0];
if (suffix)
{
NSRange pos = [spriteName rangeOfString:@"."];
if (pos.location == NSNotFound)
{
// No point, it's a base sprite, so just append.
[spriteName appendString:suffix];
}
else
{
// Append where the period was found, just before it.
[spriteName insertString:suffix atIndex:pos.location];
}
}
and assume it gets changed to this:
// We also have to add any specified prefix and (pre-period) suffix.
if (prefix) [spriteName insertString:prefix atIndex:0];
while (we_need_to_do_stuff)
{
if (suffix)
{
NSRange pos = [spriteName rangeOfString:@"."];
if (pos.location == NSNotFound)
{
// No point, it's a base sprite, so just append.
[spriteName appendString:suffix];
}
else
{
// Append where the period was found, just before it.
[spriteName insertString:suffix atIndex:pos.location];
}
}
}
I don't want to namedrop too much, but what does FileMerge (the graphical diff/merge utility that ships with Xcode) do? This:
…how thoughtful, FileMerge, you made sure to match the braces because they were at the same indentation level, and separated the related code. Couldn't have asked for more.
The usual solution in that case is to find the option to consider changes in the amount of whitespace as being not significant, and try again. But then I want to make sure I have not fumbled the indentation either, because it is something I am going to commit, so I go back to the options, disable the option, try again. Repeat for all the changes I want to review.
There has got to be a better way. Is it just me using my tools badly? Is it theoretically possible to improve this workflow? And this is a simple case, have trickier ones been solved in the abstract? How should I look for better tooling in this domain, given that this is hard to express as a search engine query?