Myers Diff Algorithm – Code and Interactive Visualization
blog.robertelder.org
blog.robertelder.org
Makes for amazing demos. Might some day be what we are all using. My hopes have been dampened severely by how long this has taken to make any head way. (And, honestly, it couples your diff tool to the rest of your tool chain rather heavily. I can see why it has a hard time taking off.)
It also supports a few other diff algorithms: `--patience` and `--histogram`, but in my experience they produce the same output as Myers in most cases.
For example preferring to split on empty (whitespace-only) lines. Almost all languages and coding styles use empty lines as a "semantic separator" marker.
This is far from a new idea. Age old Levenstein distance can be seen as a special case. Here the edit model is very simple. All letter addition, deletion, and substitutions are equally likely. More realistic a model one uses the better the results will look like provided one has enough data to train.
One could train models for specific languages (natural as well as programming). If we have language specific syntax highlighting, why not language specific edit models. One could do personalized models, etc etc.
1) convert code sample 1 to AST 2) convert code sample 2 to AST 3) do text-based diffs while paying attention to the ASTs
A closing brace is really part of the function started by the function definition and opening brace. As such, a closing brace from function X should never "match" an opening brace from function Y.
I imagine that simple chopping code into multiple text blocks, one for each function, before passing it to a "diff" routine would accomplish most of that. After all, we already chop code into text blocks by filename...
This 1983 paper is still relevant today, it's an algorithm much better suited for code diffs and I'd like to use this instead. It's the best algorithm for big code refactors. I implemented it in Go, and hope to get back to it.
Learned about it on: http://bryanpendleton.blogspot.com/2010/04/more-study-of-dif...
The title of the paper is "The String-to-String Correction Problem with Block Moves". You can search for it with filetype:pdf on Google.
Here is another link (even better quality): https://www.researchgate.net/profile/Walter_Tichy/publicatio...
For some reason, I cannot edit my previous comment :(
- single letter variables, as in the rest of mathematics
- succinct without being obfuscated
- the whole thing fits on your screen without need to scroll (no dependences, no hidden pieces)
- the complex algorithm is clarified in the text below, breaking it into smaller parts and explaining each one in detail
- comprehensive examples, figures and references
This is truly a model of exposition.
Not that efficiency really matters much for my use-case!
Edit: Read the article now. Incredibly happy to see that the implication was on purpose. :)