Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday May 04, 2008
07:53 AM

Scope Hiding and Refactoring Editors

[ #36323 ]

You know, I would really like to be able to hide outer scopes in Perl. There are plenty of times that I've worked with bad code and I would love to quickly and easily see what variables are embedded in a chunk of code which are defined in another scope. I figured out one way to do this with a primitive refactoring tool I'm working on. I shove the code into a different namespace, wrap it in a subroutine to prevent it from being executed (the code will croak() if there is a BEGIN block), and then eval it with strict and warnings. The error messages are trivial to parse and I can figure out which variables are not defined there.

This leads to my next problem: which variables are defined after that chunk of code which are dependent on that chunk of code. Trying to figure out the "extract method" refactoring means I have nastiness like this:

my ( $foo, $bar );
($foo, $bar, $baz ) = $self->_extracted_method($baz);

That raises another issue. The code must now always work in list context (let's hope you don't have wantarray embedded in the extracted code) and if there is an embedded return (some languages only allow return at the end of a method/subroutine), then this could also screw things up.

The more I play with this, the more I understand why Adam Kennedy struggled with a refactoring editor.

However, if I go for an 80% solution and I write tests (which, as you know, I do), then I could execute a refactoring and then automatically run all tests for the refactored code.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.