Comparing code

diff is a classic tool when comparing text files, redirecting its output to less or other pager.

This utility find differences between the content of two files, but don’t keep track about context (e.g. class or method where a difference occurs). That’s a good reason to use different files for different classes, instead of storing thousands of lines dealing with different tasks on the same file (for those who do not mind about how smart programs look when written with good taste ;) ).

Using one file for each class, diff provides context information showing its name.

vimdiff provides another way to see differences in code, putting lines side by side. Some other open source tools based on the same concept are available on Windows and Linux:

* Meld: beautiful GTK+ 2 or 3-way comparison and merge tool. Written in python but available, AFAIK only on Linux
* Kompare: included in KDE, does 2-way comparison and merge in a similar way to Meld, with a cute interface too. Currently, I think it hasn’t been ported to Windows
* Win Merge: only Windows :(
* Tortoise Merge: only Windows :(
* KDiff3: excellent multiplatform tool (Windows, Mac OS, Linux, UNIX…) built using Qt Toolkit. Allows searching for differences line by line, but also inside the characters in a line, showing or hiding blank lines, “important” and “not-so-important” lines… And supports 2-way or 3-way modes, and directory comparing. Development looks very active.

Wikipedia holds a broader list of file comparison tools.


About this entry