Just A Summary

Piers Cawley Practices Punditry

Crossing the Rubicon. Again

In 2001, using an idea from James Duncan, who blames Damian Conway for getting him thinking on the right lines, I wrote a proof by implementation of the Extract Method refactoring for Perl. Though I say so myself, this was a Big Deal – Martin Fowler calls Extract Method the Refactoring Rubicon – once you have a tool to help you do that refactoring automatically, you can probably implement the rest of the Smalltalk Refactoring Browser and free yourself to think more about the interesting aspects of programming.

And nothing happened.

Five years later, I mentioned this to Jesse Vincent at EuroOSCON. He got that “You interest me strangely!” look, so I verbally sketched out how it worked, which induced the “I must hack now!” look. I headed off to another session and left Jesse to scratch his itch.

About 3 hours later, we hooked up again, and he showed me the vi plugin he’s hacked up which implements an ‘extract function’ refactoring. So we sat down together and made it extract a method correctly.

At this point, magic happened. Jesse’s original script was, putting it politely, very hacky. It’s less hacky now, in part because it’s been refactored with the assistance of this cool new tool he’d just written to extract methods from Perl code.

Published on Thu, 21 Sep 2006 07:33:34 GMT by Piers Cawley under , .

If you liked this article you can add me to Twitter
  • Gravatar

    By Geraud Fri, 22 Sep 2006 00:33:34 GMT

    Let me tell you Sir how mad I am.

    Not only you disapear in a JustLikeThat manner after months (if not years) of truly enlightening perl 6 summaries, but when you condescend to push a one-liner in your use perl journal it’s only to brag about this! You Sir, should be ashamed of yourself. How many small wonders like this one should I look for in your blog?

    Anyway, in order to use this life-saver piece of code, I did the following :

    - put the file in $PATH, chmod the file, fix the shebang
    - add the following in my .vimrc :
    map ,pex <Esc>:’<,’>! extract<CR>

    Is there anything else I may have missed?

    Best Regards,

    G.


  • Gravatar

    By Piers Cawley Sat, 23 Sep 2006 07:33:34 GMT

    Not that I can think of. For my next trick I intend to implement the ‘Rename Variable’ refactoring and start adding tests.

    Then I shall go in search of grant money to fund developing a rather more comprehensive suite of refactorings.

    Sorry about stopping with the Perl 6 Summaries. Life rather got on top of me I’m afraid. Ann Barcomb’s doing a fabulous job with them now though.


  • Gravatar

    By Geraud Sat, 23 Sep 2006 07:33:44 GMT

    You don’t have to be sorry at all. $Life, for some reason I didn’t figure out yet, has a real something for getting in the way. I for one am just glad I found you again.

    Can’t wait for your next trick. :)

    G.


  • Gravatar

    By Aristotle Pagaltzis Sat, 23 Sep 2006 07:33:54 GMT

    placeholderHmm. That script eats a ton of memory at first, and then gets killed for needing too much of it, before it manages to produce any output. What am I doing wrong?


  • Gravatar

    By Geraud Sat, 23 Sep 2006 07:34:04 GMT

    Well, I can’t tell for everyone, but here’s how I’m using it.

    In vim, I’m selecting several lines in visual mode, then type ’,pex’ and I get all the selected code in its own method and an extra line with a call to the newly created method with all the params required. So far I have used it on simple scripts (as in no-complex-constructs and no-tricky-perlisms) and it’s a bliss.

    Hope this helps.

    G.


Comment Crossing the Rubicon. Again

Powered by Publify – Thème Frédéric de Villamil | Photo Glenn