Hey programmers – what if I told you that there was a fairly interesting problem out there, that would probably be just a few weekends of work, and which if you implemented it you could find your code part of the toolset of a significant proportion of software developers worldwide (especially if you open sourced it)?
Anyone familiar with source control systems like svn and git will be familiar with the occasional need to “merge” changes. This is to take changes to one version of a file, and apply the same changes to a different (but not too different) version of that same file.
Today’s merge tools, at least to the best of my knowledge, basically treat all text files the same. Whether its Java, HTML, C++, or CSS, as far as the merge tool is concerned, they are all just lines of text.
This works ok in many situations, but it can get tripped up by situations like this:
Book book = new Book( String name, int length);
Let’s say we change this to:
Book book = new Book(String name, int length);
A programmer knows that all we’ve changed here is formatting, but a merge algorithm will see this has two lines deleted, and one line changed – quite a major alteration.
It is true that passing both files through a formatter would help in this case, but there are many other situations where it wouldn’t. Consider renaming a variable throughout a file, inlining a variable, and other common refactoring operations.
My proposal is fairly simple. Rather than treat Java files as simple text, we parse the files into an “Abstract Syntax Tree” using a Java parser, maybe even matching identifier names like variables, and treat the merge operation as a merge of these trees, rather than simple lines of text.
After the merge we convert the resultant tree back to text, perhaps even formatting it as we go.
The result of this, I suspect, would be dramatically more robust merge operations.
So what would be involved here? Well, it shouldn’t be necessary to write a bunch of parsers, because these already exist for most languages. The main thing would be the tree merge algorithm, which would be a neat self-contained computer science project. Perhaps there is even an off-the-shelf open source tree merge algorithm out there.
Regrettably I’ve already got a bunch of projects on my plate already, but perhaps there is someone out there interested in taking on this challenge? If they did I could almost guarantee that the resultant software (which I assume they’d open source) would be very widely adopted.
If you are interested I’ll be happy to help and advise. You can email me at email@example.com.