Not Quite Getting It
Stories of obfuscated Perl written by incompetent people (or sadists) are legion. But sometimes you come across some code that appears as if it was mostly written by someone who knew what they were doing, but seemed to be missing some crucial bit of information.
Today I saw a set of OO Perl packages that appeared perfectly cromulent, until I noticed that every method call looked like this:
sub foo {
...
$self->{args} = [ 1, 2, 3 ];
$self->method;
}
sub method {
my $self = shift;
my @args = @{ $self->{args} };
...
}
The rest of the code was clear, well-structured, logically modularized, and even unit-tested. Apparently, this otherwise perfectly good programmer was either completely unaware that Perl methods can take parameters, or, for reasons that are lost to the mists of time, chose not to use them.
Weird.
That's a silly code. If someone knows about unit testing, must also know not to do silly things IMNSHO.
That's what makes it so strange. It's one thing if it's written by a n00b who doesn't know any better, and randomly stumbles across something that works, but quite another to see such bizarreness in the midst of otherwise good code.
My guess (and it will have to be a guess, since the author has dropped off the face of the earth) is that this was some sort of ill-conceived attempt at premature optimization.