Felipe call for a better diff


Blogs: Felipe call for a better diff

  1. Felipe call for a better diff (1 messages)

    Why is it that developers will argue excessively about where should the curly braces go. Part of the answer is that how things look make coding a very personal experience. Different styles can sometimes be difficult to get used to. But as trivial as the question sounds, a team that cannot follow a style guideline can render tools such as diff useless. According to Filipe Gaucho, it doesn’t have to be this way. As Felipe recounts, diff is a tool developed in the early 70s, a time when the computing landscape looked very different
    The common tools available today relies on the longest common subsequences (LCS) to compare the sequence of characters to detect differences between two files. The appeal of such algorithm is that it is fast and robust. It was designed in the Early 70' and it was designed to be clean and to consumes small amount of resources - memory and cpu.
    While the tool was easy on computers, it is a bit harsh on the users (developers). Felipe asks the question; are these code fragments really different?
    • private int i = 0;
    • private int i = 0;
    • /* are these code fragements really different? */ private int i = 0;
    • // todo: ….. private int i = 0;
    From the compilers point of view these code fragments are the same. But diff is indifferent to syntax and will highlight these fragments as all being different. Teams that do not follow a style guideline and/or are constantly fiddling with the format risk serious downstream difficulties with their source code control systems, Filepe’s answer, it is time for a syntax aware diff. If you were to combine a syntax aware diff with formatting tools that works as you import code into your IDE, the effect would be that everyone could look at the code according to their own preferences. The question is, why can’t we do this;
    • A developer create and commit a source code using Eclipse and following the Sun Code Conventions
    • Another developer checkout the code using NetBeans and format that code using Jalopy. Then commit the code
    • The first developer open the modified source code and observe it exactly with the same format he committed it in the first time
    Is it past time to upgrade our tools?

    Threaded Messages (1)

  2. use tokenizers[ Go to top ]

    Another simple possibility to improve diff would be to use format sensitive tokenizers. Regards, Holger