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
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Don't be so hard on yourself (Score:3, Funny)
True, most Perl programmers would have trouble maintaining it, and this is a valid concern.
Maybe you should comment it heavily and stare at it until you understand it forward and backwards. There's a lot to be gained by functional programming. Generally, the fewer the intermediate variables and the less the code, the _better_ the maintenance in the long run.
Obnoxious comment. Could you make it even more functionally gnarly with something like this (untested)?
my %names =
map { @$_ }
mapcaru( sub {[@_]}, \@name_ids,
[map { join ' ', @$_ }
map { [non_empty(@$_)] }
mapcaru(
sub {[@_]},
@{mapcaru(
$get_common_words,
[map { $_->[0] } @bad_names] )})]);
?
Don't hit me!
Reply to This
Re:Don't be so hard on yourself (Score:3, Informative)
Aack! I'll pretend you didn't write that :)
One of the reasons why I break things into smaller steps like I did is that it's easier to insert debugging statements. As for the above, I wound up using an entirely different strategy suggested by Gav.
Re:Don't be so hard on yourself (Score:1)
If I have something in an extreme functional style and I need to debug it, I just replace one of the function calls with a call to a function_debug wrapper. In my above extremely functional style, you could add map_debugs or mapcaru_debugs which would print arguments and then apply the map or mapcaru function.
One added advantage of this is that you can get all your maps or mapcarus to confess at once, often yielding une
The Functional Approach (Score:2, Funny)
You could always make the arguments of a smug Lisp weenie:
As for me, a smug Perl weenie, I think you may go better pulling out a couple of subroutines. I don't write a lot of loops anymore.
Re:The Functional Approach (Score:3, Funny)
-Dom
Re:The Functional Approach (Score:2, Funny)
I could have sworn I put on my "maintainable code" hat this morning. Oh well!
If your Ward Cunningham number is appropriately low, you'll know a Confident XP Weenie would say, "What would happen if you extracted a couple of those transformations into their own methods?" Unlike smug weenies, confident weenies are subtle.
Re:The Functional Approach (Score:2, Funny)