I’ve been facing a problem recently, in which I want to optimize two programs.
For that, I wanted to create some kind of “Common Interface” which I could reuse between my two programs.
However, the code of these are approximately 1000 lines, and I don’t want to spend a big amount of time checking if this or that function is the same as this one and whatsoever.
So I used BOUML to check the similarities between class diagrams. But I wonder if there is a global way to do such a study ?
1
If both programs are from the same author, and you have the suspicion that the author might have copy-pasted some functions from one program to the other, using a tool like “diff” (or WinDiff or WinMerge) may help you to find some of that code blocks. Of course, this works only if you do not have too many source code files (which I guess is unlikely, since 1000 lines of code is not really huge).
However, if you want to find functions or code blocks which do essentially the same, but the functions in stake have a completely different implementation, there is IMHO no short-cut to learn and understand what the code does (at least the parts you want to merge). Before refactoring common functionality, you have to be sure that the code you want to refactor really does the same. You may not have to understand the full code, but even for identifying candidates, a rough understanding of the functions is IMHO necessary.
2
Well, I assume that you know the functionality of both programs. Extracting the common interface is a regular refactoring job since you probably just want to remove code duplication.
So just load your two programs in any IDE and look at the outline view where the classes/method signatures are shown. Since you know the functionality of both programs it shouldn’t be a difficult task to find the duplicate code parts.
3