Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
So I stumbled across the following:
sub schema_for_class {
my ( $self, $class ) = @_;
return grep { $_ }
$self->table_for_class($class),
$self->indexes_for_class($class),
$self->constraints_for_class($class),
$self->view_for_class($class),
$self->insert_for_class($class),
$self->update_for_class($class),
$self->delete_for_class($class);
}
That's a lot of repetition and therefore a lot of noise. So I reworked it a bit.
sub schema_for_class {
my ( $self, $class ) = @_;
return
grep { $_ }
map {
my $method = "${_}_for_class";
$self->$method($class)
} qw(
table
indexes
constraints
view
insert
update
delete
);
}
Now I feel like a maintenance programmer can glance at it and get an idea of what's going on. But I do worry that sometimes I'm refactoring so aggressively that maybe it's getting too abstract. I do try and find a balance. I'm just not sure that I balance quite where others do.
A Fine Refactoring (Score:1)
I did a similar refactoring just tonight with far fewer similar method names.
Re:A Fine Refactoring (Score:2)
With all due respect, I know you're going to get it. I've seen your work (hell, I've worked with you) and I know that you won't blink when you see that. I just worry about the poor maintenance programmer. I'm not too terribly worried as I think that the maintenance programmer who works on this code had better be pretty damned nimble with the Perl chainsaw in the first place, but then, I'm so used to seeing this that I've no idea if it's obscure or not.
Drawing the line (Score:1)
The important thing is that you’re thinking about it rather than just refactoring it because you can. (And I guess that this example must be close to your own borderline, or you wouldn't be asking about it.)
Re:Drawing the line (Score:2)
Re:Drawing the line (Score:2)
—Theory
Re:Drawing the line (Score:1)
Re: (Score:1)
Only if he actually composes them as strings. The version I posted [perl.org] has the clever bits save for interpolation, and searchability wouldn’t suffer with it.
Re:Drawing the line (Score:2)
unnecessary (Score:2)
Re: (Score:1)
I share your instinct and to refactor this, but your refactored version would strike me as odd immediately upon finding it: why
grep { $_ } map { $foo }when that’s exactly the same asgrep { $foo }?And I think the interpolation is just too clever. It also makes it unnecessarily hard to add or remove method calls that may not follow this naming scheme, should that ever be necessary. So I’d simply say
Re: (Score:1)
(No, I didn’t intentionally forget to convert the spaces to a tab in
my ( $class ) = @_;.)Re: (Score:1)
qw(
table_for_class
indexes_for_class
constraints_for_class
view_for_class
insert_for_class
update_for_class
Re: (Score:1)
Ack! Of course. Sigh.
I guess one could use
but I’m not sure how well advised that is…