Refactoring, B::* and more Smalltalk theft

pdcawley on 2002-03-19T09:03:11

So, I've been stalled on the refactoring engine for a while now, the euphoria of getting a working 'extract method' prototyped wore off and motivation suddenly fell away as well.

But people have been nagging at London.pm, and a few comments from Smalltalkers on various mailing lists about the ease of programming when you've got a refactoring browser got me interested again.

So, I installed Squeak (a free Smalltalk) and installed the Squeak Refactoring Browser to see how they did it, and its fascinating, if sometimes hard to follow (have to resist the temptation to go digging too deep into the how and look instead at the intent).

One of the things that my prototype doesn't do is to check pre and post conditions before committing the refactoring. And it should do. For instance, it checks to see if the chunk of code that's being extracted is being treated as an lvalue in the calling context. It does this by inserting a placeholder method call in the caller code (replacing the extracted code), compiles the calling code and then walks the optree to find the placeholder and checks that it's not being used as the target of an assignment.

Time to see how B::Xref does it methinks... I'm looking forward to being able to do:

$ sourcegrep 'calls(foo)' *.pm
FooUser.pm:3:    $self->foo();
SomeClass.pm:11:       $self->foo;
or
$ sourcegrep 'implements('bar') *.pm
Parent.pm:10:sub bar { croak "Abstract method bar called"}
Child1.pm:50:sub bar {
Child2.pm:35:sub bar {
After all, a working sourcegrep could be used by more than just a refactoring browser...


B::Xref and sourcegrep

rafael on 2002-03-19T10:41:29

FWIW, I've fixed a few minor bugs in B::Xref recently. This module is not perfect.

On the other hand, look at Schwern's Module::Info : it provides a pfunc utility to "search the named files for all calls to the given subroutine."