Page 1 of 1

refactoring tools

Posted: Tue Nov 07, 2006 10:17 pm
by alex.barylski
I'm sitting down today thinking...I'm gonna write a tool which removes code duplication or at least suggests when refactoring might be of use....

Then it hits me...instead of using a diff, if you abstracted slightly more and analyzed constructs, statements, etc...as a whole instead of on a character by character (or token) basis...you might be able to locate code fragments which are not just syntactically similar...but semantically as well...
if($a == 'SomeDude')

if($someVar == 'SomeDude')
Obviously the above duplicate code would be pointless to refactor, but I am sure in complex codebases you could find code which could be extracted and refactored... :)

Any articles on the subject, etc???

Not looking for the first 5 tools you can find on google eh... ;)

Cheers :)

Posted: Tue Nov 07, 2006 10:39 pm
by feyd
It's still a diff, just not as strict. Which is likely not realistic to write when we are likely far faster at understanding when something is or isn't similar enough to be considered refactorable.

Posted: Tue Nov 07, 2006 10:51 pm
by alex.barylski
feyd wrote:It's still a diff, just not as strict. Which is likely not realistic to write when we are likely far faster at understanding when something is or isn't similar enough to be considered refactorable.
While I agree as developers were capable of making such descisions on our own...On a large codebase which has been handed down to us...it could take an eternity to find, not to mention remember similar code fragments...

Having a diff engine scan a source tree and locate fragments in functions, which are not byte for byte but similar in structure...IMHO could speed up the process tremendously...

Posted: Wed Nov 08, 2006 1:04 am
by Chris Corbyn
I'd build a wrapper around diff myself. Seems sensible.