• The man who couldn't refactor

    For the past few months, I've been slogging through some PHP code written by a solo programmer with no real oversight from other programmers. His code is a monoculture.

    I found this bit of code today that just sums up his unwillingness, or perhaps inability, to refactor.

    if (substr($libtest,0,12) == "FOO COUNTY")
    $foocounty=$getmultiples=1;
    if ((substr($libtest,0,12) == "FOO COUNTY") && ($state=="TX")) {
    $foocounty=$getmultiples=0;
    $foocountytx=$getmultiples=1;
    }
    

    Just read those lines of code and you can recreate the crime in your head. First there was a customer in Foo County. Then, we had to handle a different Foo County, but this Foo County was in Texas. He couldn't even be bothered to change the initial test to be more specific, or to modify the existing code. His solution was the simplest thing that could possibly work, and was also the worst: Reversing the effect of the first check for Foo County. There's also no checking for non-Texas, non-original Foo County, but when I checked I found that we have customers that are in Foo County in THREE different states.

    The programmer no longer works for us, so I'm unable to ask him about his motivations. I'm fascinated by the mindset that is unable to do the barest rework necessary.

  • Make your own mini CPAN

    Ricardo Signes' marvelous module CPAN::Mini just got an update today, and it reminds me to tell you all how great it is to be able to have a small version of the CPAN on your local hard drive, especially on a laptop. The included minicpan program makes it trivial to update your local archive.

    First, I make a little ~/.minicpanrc that looks like this:

    local: ~/minicpan/
    remote: http://cpan.pair.com/pub/CPAN/
    also_mirror: indices/ls-lR.gz
    

    And then I run minicpan every so often. This pulls in the latest version of each distribution, and deletes ones that are obsoleted by newer versions. When I run minicpan, it looks like this:

    $ minicpan
    authors/01mailrc.txt.gz ... updated
    modules/02packages.details.txt.gz ... updated
    modules/03modlist.data.gz ... updated
    mkdir /tmp/Woq_DHsWsN/indices
    indices/ls-lR.gz ... updated
    indices/ls-lR.gz ... updated
    mkdir /home/andy/minicpan/authors/id/G/GR/GROMMIER
    authors/id/G/GR/GROMMIER/Text-Editor-Easy-0.01.tar.gz ... updated
    authors/id/G/GR/GROMMIER/CHECKSUMS ... updated
    mkdir /home/andy/minicpan/authors/id/Z/ZO/ZOFFIX
    authors/id/Z/ZO/ZOFFIX/Acme-BabyEater-0.01.tar.gz ... updated
    authors/id/Z/ZO/ZOFFIX/CHECKSUMS ... updated
    ...
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEROSS/DBIx-StORM-0.04.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/Test-WWW-Selenium-1.13.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/mocked-0.07.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LO/LOCATION/Geo-IP2Location-2.00.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LO/LODIN/Regexp-Exhaustive-0.03.tar.gz ...done
    

    Currently the repository is only 846M of disk space. Who doesn't have an extra gig lying around these days?

    uniqua:~/minicpan $ du -sh
    846M	.
    

    I also point my CPAN shell configuration to use the mini CPAN as its source of modules by prepending file:///home/andy/minicpan to the list of URLs it checks.

    Thanks to Ricardo for putting out this great tool, and Randal Schwartz for the original column on which it was based.

  • More vim goodies for Perl 5.10

    Rafael Garcia-Suarez has posted his modifications for vim to support Perl 5.10. His are a good deal more complete than the simple modification I posted last month that just covers the say keyword.

  • Take a nibble of Perl 6 with a microarticle

    If Perl 6 is a little daunting, take a smaller bite by reading one of Adriano Ferreira's Perl 6 microarticles. The index of articles is on the official Perl 6 wiki on the page called Perl 6 microarticles. As of now the list of articles is:

    For more news of Perl 6 and Parrot, please keep an eye on rakudo.org.

  • Designing too far into the future

    Max Kanat-Alexander has a new blog up called Code Simplicity, and I'd love it for the name alone. His latest post, "Designing Too Far Into The Future", talks about the perils of trying to predict the future and guess what your code will have to do down the road. In the XP world, the term that gets thrown around is YAGNI, for "Ya Ain't Gonna Need It." When you have to write a report and you start by writing a report generator, that's a big violation of the principle of YAGNI.