Thursday, July 29, 2010

Winner of the WTF/loc award

To gauge the quality of code, we've all seen the metric called WTF/minute.

I'm inventing a new metric, called the WTF/loc, based on this very short snippet of code.
use strict;
my $cmd = "perl " . shift;

my $h = <STDIN>;
while ($_ = <STDIN>) {
        open (S, "| $cmd");
        print S $h;
        print S;
        for (2..1000) {
                last unless $_ = <>;
                print S;

A few comments to explain what's going on would have made this snippet of code much more maintainable.


Anonymous Dave Carver said...

And thus...why I have migrated away from Perl. It's full of WTFs per line.

7:11 AM  
Anonymous Miles said...

When I was first starting out with 4GL data base tools in 1990 or so, we had a convention whereby we added a side comment to code with our initials along with rationale etc.. Our firm's owners had taken on the dubious job of "assisting" an in-house (ahem) developer for a membership management database. This basically involved trying to figure out what the guy was trying to do and actually making it work while preserving this guy's job since he was the one paying us. So one day I get a call from this guy, wondering if we've added staff to the project and why he hadn't been told. "This new WTF person seems to be doing a lot of work on the code." It was more than a bit embarrassing as of course he soon figured out the true meaning.

11:47 AM  

Post a Comment

<< Home