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 ]

jarich (4909)

jarich
  (email not shown publicly)
http://www.perltraining.com.au/
AOL IM: ManningBear (Add Buddy, Send Message)

I run Perl Training Australia [perltraining.com.au] with pjf [perl.org] and do a lot of the course writing and maintenance. I also organise the courses we run, so if you want one, just ask. I hang around a bit on Perlmonks [perlmonks.org] and also help run Melbourne Perl Mongers [pm.org].

Journal of jarich (4909)

Monday January 23, 2006
02:38 AM

Crufty code

[ #28437 ]

I'm a infrequent reader of http://thedailywtf.com/, and I know it's true, because I've seen similar code out there.

Some pieces of code, though, are so lanugage specific, that although they deserve to be show-cased on such a site, they're not suitable for that particular one.

Take today's example (from a popular CPAN module, no less):

unless (ref $self) {
    my $class = ref($self) || $self;
    # etc.
}

Classic code cruft! If ref $self wasn't true a moment ago, it's not suddenly going to become so now!

This is a very mild example of crufty code. I can easily see it happening, yet it's obviously wrong, and still in there!

Another example, from the the same module, is overly complex (identifying details obscured for the time being):

$object->Some::Module::signature([map {join $;, $_->[0], Some::Module::disqualify($_->[1]->{'type'} || '')} @values]) if @values;
return wantarray ? @values : $values[0];

I don't normally go hunting for code to complain about. I've written enough of that, and maintained other people's enough to satisfy any urges I might have in that direction. My hunting today, was to find where, in a very useful, but complex module, things were going wrong. And crufty code (not to mention very few comments) makes it just that little bit harder.

I'm not saying that the last example is bad code, but I do believe it is needlessly complex. I suspect it started out simple, and easy to understand, and then grew into that. Such is how crufty code happens.

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.