[Chicago-talk] Sharing my pain

Jim Thomason jim at jimandkoka.com
Fri Oct 13 13:29:11 PDT 2006

>Ok, I'll bite.  What's so terrible about this code?

Just the stuff that jumps out at me, I'm sure there's more:

sub findSprokets {
    my $sprokets = '';
# this should be my $sprokets = []; (maybe my @sprokets = ();) you'll
see why later
    my @tmp;
#should be down below.

    $sproketDat = "/tmp/sprokets.dat"
#hardwired to some value. Might be nicer to be able to pass this in.
Maybe leave this as a default, perhaps in a config file.

    my $sproketAccum = qx(cat $sproketDat);
#shells out to cat to read in the file, very non-portable, very sloppy.
    $sproketAccum =~ s![\n\s\t]!!g;
#\n and \t are superfluous. just \s works. At that point, tr/\s//d is better.
    @tmp = split(/\+;/, $sproketAccum);
#should be my @tmp =, no reason to declare up above.
    foreach (@tmp) {
        unless (m!foobar!) { s!^foo!!g }

    my $sp;
    foreach $sp (@tmp) {
#old skool! foreach my $sp is better
        $sp =~ s!\\!!g;
        $sp =~ s!\n!!g;

        if ($sprokets) { $sprokets .= ' ' }
        $sprokets .= $sp;
#egad. He's using a space delimited string as a pseudo array to split out later!
# push @$sprokets, $sp;
    return $sprokets;

my $tmp = findSprokets();
@sprokets = reverse sort( split(/ /, $tmp) );
# scrap this in favor of @sprokets = reverse sort @{ findSprokets() };
#the reverse, sort, and scalar/list context could also be moved into
the function.

But, I don't see anything in there that I'm going to fault perl over.
Bad programmer? You betcha. Looks like someone who started on an older
version of perl and has a shell scripting background. A past co-worker
said she used to think of perl as just glorified shell scripting, and
it wasn't 'til later that it clicked with her about why it was neat
(or words to that effect). I don't think it's clicked with this person

I think your programmer friend could have (and would have) written it
just as poorly in python or java or anything else.


On 10/13/06, Alan Mead <amead at alanmead.org> wrote:
> Shawn Carroll wrote:
> >initiative.  We came accross the lovely code below.  He said this is
> >the kind of code people talk about when they say perl isn't a great
> >language.  After reading it, if this indicative of some perl out
> >there, I'd have to agree.
> >
> Ok, I'll bite.  What's so terrible about this code?  Using bangs for
> delimiting m// and s///?  A complete lack of comments?
> I ask because I come across module code all the time that I cannot
> read.  But this was no sweat, even though I was unfamiliar with stuff
> like qx{} .. it was clear what was going on.
> --
> Alan D. Mead, Ph.D. : amead at alanmead.org : 815-588-3846
> What is wanted is not the will to believe, but the will to find out,
> which is the exact opposite.
>                 -- Bertrand Russell, "Skeptical Essays", 1928
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

More information about the Chicago-talk mailing list