Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compare Programs What do they need to do to be helpful? Copyright © 2016 Curt Hill.

Similar presentations


Presentation on theme: "Compare Programs What do they need to do to be helpful? Copyright © 2016 Curt Hill."— Presentation transcript:

1 Compare Programs What do they need to do to be helpful? Copyright © 2016 Curt Hill

2 Audience Participation Under what circumstances would I want to compare two files? When would I want to know that they are different at one or more characters? When would I be interested in finding inserted or deleted lines? Copyright © 2016 Curt Hill

3 Beginnings Most systems had a very simple comparison –Such as the DOS COMP command This has gone through several revisions In the early days it quit after the first difference It answered the question: –Are these two the same? –Yes or no Copyright © 2016 Curt Hill

4 Later You have the current version on your computer It first looks at the size of the two files If they are the same it continues Next it compares each pair of characters –It shows the differences in the two different characters Only slightly better Copyright © 2016 Curt Hill

5 The Program Comp is comparatively easy –Sounds like a 160 or 161 program –Need files –Read each file in, one character at a time May be helpful for data files, but not much help in development –This is not how source files are changed Copyright © 2016 Curt Hill

6 UNIX and Developers The original purpose of UNIX was to be a development platform –Programmers would have access to smaller machine for development –When the program was “correct” it was usually moved to a production machine –The production machine was expensive and tightly scheduled Many of the utilities on development machines were aimed at programmers One such is Diff Copyright © 2016 Curt Hill

7 Diff Original is about 1974 –Author is Douglas McIlroy Purpose is to compare files and find differences It will attempt to find the minimum insertions and deletions that transforms one file to the other This makes it much more complicated than programs like COMP Copyright © 2016 Curt Hill

8 Updater Consider a command line updater It takes as input two files: –A source code file (such as x.cpp) –A command file It produces the new source code file –That replaces x.cpp It applies the changes introduced by the command file It has two kinds of commands: –Insert some lines between two lines –Delete one or more lines Copyright © 2016 Curt Hill

9 Editor The updater is not what we would normally use to make changes in a program –We would use an editor Any set of changes made by an editor could be converted into updater commands The editor would be easier, but the updater is more mechanizable Copyright © 2016 Curt Hill

10 Compares Every good comparison program should have one or both of the following goals: –Generate the updater commands that are needed to transform one file into another –Show the developer these changes in a more gracious way Notice that this eliminates COMP as a good comparison program Copyright © 2016 Curt Hill

11 How? The algorithm is a little more than we want to consider here so we will greatly abbreviate Once a mismatched pair of lines is found attempt to find the longest matching sequence of lines following the two This is definitely not a 160/161 program! Copyright © 2016 Curt Hill

12 WinMerge One example that I am partial to is WinMerge A GUI comparison program Graphically displays the differences Will generate the command files as well The download link is on the web page A couple of screen shots follow Copyright © 2016 Curt Hill

13 Showing Differences Copyright © 2016 Curt Hill

14 Command file Copyright © 2016 Curt Hill 2c2 < Purpose of program: Count or number lines --- > Purpose of program: Count and/or number lines 5d4 < 9d7 24,25c22,24 < int files = 0; < if(argc < 1){ --- > int fIles = 0; > if(argc > 1){ >

15 Finally Indispensable tools for finding how a source file has changed –I only use WinMerge to inform me Also a foundational element in version control –Most version control systems have their own diff or diff-like program –They will either store the original and the changes needed to make current or the reverse Copyright © 2016 Curt Hill


Download ppt "Compare Programs What do they need to do to be helpful? Copyright © 2016 Curt Hill."

Similar presentations


Ads by Google