refactoring tools

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

refactoring tools

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'd build a wrapper around diff myself. Seems sensible.
Post Reply