Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Refactoring copy-pasted code

by dwm042 (Priest)
on May 05, 2009 at 21:48 UTC ( #762097=note: print w/replies, xml ) Need Help??

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.


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!!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://762097]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2023-06-04 23:47 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.