Teach me refactoring from my commits!

I find it hard to learn purely by abstract theory - I need practical examples to illustrate the theory I just learned. I also need practice, and preferably, supervised practice, so my mistakes can be caught early and/or more efficient ways can be shown to achieve the same thing I just did.

With this background, it's not surprising that when I heard about a product that started to do semantic diffs for version control I was reminded of the Refactoring Golf concept from the first Software Craftsmanship London conference - and the two ideas just clicked into this great (ok, I'm biased) idea to try to derive the most efficient refactoring steps for that particular commit I just made.

The pieces required for this project are all already in place:

  • we have parsers for languages, and many are available as libraries to traverse ASTs
  • most version control systems have libraries to read from them
  • there are tons of well-defined refactorings known, that can be used as operations in the transformations from state A to B
  • optimization algorithms are plentiful - for a proof of concept, the String Distance Transformation algorithm could be used

Thus such a program script could be added as a post commit hook, or simply could be run on the workspace copy, using the diff against last committed version, and it could tell me that I might have:

  1. renamed variable login to username
  2. converted username from local variable to method parameter
  3. extracted method lock_customer_acocunt from method login

I'm pretty positive even experienced refactoring practitioners could learn new tricks, and newbies would be delivered concrete refactoring examples tailored to their very codebase.

Please, someone with enough free time, go and make such an app!

Does this idea make sense for you too, or just me? Let me know via email (hello at site domain) or on twitter (@zsepi)!

What do you think? I would love if you would leave a comment - drop me an email at hello@zsoldosp.eu, tell me on Twitter!

Your email address