http://qs1969.pair.com?node_id=762097


in reply to Refactoring copy-pasted code

szabgab++. This isn't uncommon. I have near-duplicate issues in one instance that is at the level of over 25 near duplicate bodies of code (involving 6-12 scripts) and another involving PHP whose near duplication numbers into the hundreds of scripts. If people can come up with rational means to handle near duplicates in this kind of domain range, I'm all ears.

David.

Replies are listed 'Best First'.
Re^2: Refactoring copy-pasted code
by jvector (Friar) on May 07, 2009 at 16:46 UTC
    I have found the 'ediff' code-merging tools within Emacs useful for situations that are kind of like yours. There is an 'ediff-buffers' command that splits the screen highlighting the detected differences between the code in two edit buffers, and allows you to step through the list of differences. Single keystrokes 'a','b' will put what is in buffer A into the corresponding difference in buffer B, and vice versa. There are many other things you can do in this mode as well. Emacs also provides 'ediff-buffers3' which does 3 files at once, and 'ediff-directories' which sets up a 'session' going through all the files in a pair of directories. I might feel inclined to load up scripts A and B, copy one of them to a new file AB, and manually construct AB to be an abstracted union of the two. You could then do the same with script C, then D...

    Hey!! Wait! This isn't my signature!!