Month: January 2008

Vim tricks for Perl

January 23, 2008 Tools 1 comment

This thread on use.perl.org points to some cool vim support for Perl. I’m not sure I like all the doodads in perl-support.vim, but I did add this to my .vimrc:

autocmd FileType perl :noremap K :!perldoc <cword>
<bar><bar> perldoc -f <cword><cr>

Now hitting K in vim runs perldoc or perldoc -f on the word under the cursor.

The man who couldn’t refactor

January 21, 2008 Code craft 1 comment

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

January 21, 2008 CPAN, Tools No comments

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

January 21, 2008 Tools No comments

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

January 18, 2008 Perl 6 No comments

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.

Perl 6 on Parrot is now known as Rakudo Perl

January 16, 2008 Perl 6, Rakudo 21 comments

For some time now, there’s been confusion about the multiple versions of Perl 6. Per Larry’s wishes, Perl 6 is a specification of the language, and not an actual implementation. There will also be no “default” implementation of Perl 6. Pugs has been going strong for a while, based on Haskell. We’ve been talking about what to call Perl 6 that runs on Parrot, and Patrick Michaud worked with Damian Conway to come up with it: Rakudo.

It’s a name the Damian has discussed before, and Yours Truly just so happened to own rakudo.org, hoping to be able to use it for something good and Perly. For a while, it hosted wikis that are now over at perlfoundation.org, and it’s sat idle since then. I’m glad I didn’t let it lapse, because now it can be an information center for the project. So far I’ve got a blog up, and I hope we can get more excitement about the project going as we post more details about the project there.

Read more about why “Rakudo” and the future of the project over at the brand new Rakudo.org.

Designing too far into the future

January 15, 2008 Code craft 2 comments

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.

OSCON 2008 Call For Participation is now open

January 14, 2008 Conferences No comments

Peter Scott sent in this call for participation for OSCON 2008.

O’Reilly Media has announced their Open Source Conference Call for Participation.
OSCON, which started as The Perl Conference in 1997, hosts the 12th annual Perl Conference this year. The OSCON Perl track review committee invites presenters to submit proposals for talks about the great things they’ve been doing with Perl. Make their job hard!

This will be the breakout year for Perl 6 (maybe this is the Christmas???), and we will feature it at OSCON. We don’t assume that we already know everyone who’s got a Perl 6 talk for us; if you’ve got something interesting to tell people about Perl 6, submit a proposal.

We are equally interested in Perl 5 presentations. This has been an exciting year for Perl 5: the Perl 5 Porters released Perl 5.10; perlbuzz readers recently heard all about Strawberry Perl; and Moose, a new object system for Perl 5, is gaining in popularity. We continue to hear stories about how Perl has saved jobs and money, and made work fun. Let’s see your presentations on enterprise-scale Perl applications and infrastructure, and the coolest modules, hacks, and techniques for using Perl for Stuff That Matters.

There’s something special about the Perl community, and you can see it at OSCON
thanks in no small part to the excellent presenters who turn out for it
each year… so join them in 2008! See http://en.oreilly.com/oscon2008/public/cfp/13 for essential advice on submitting your proposal. The deadline is February 4, so start working on those proposals now!

Peter Scott wrote Perl Medic and Perl Debugged and is a Perl trainer. He’s presented at the Perl Whirl, YAPC, and OSCON, for which this year he is on the Perl track review committee.

How to: Create database columns that contain only digits

January 13, 2008 Databases 2 comments

I see this missed so many times I have to bring it up here: “If you have a database column that contains only digits, but will not perform calculations on it, make it a character column.”

You CAN store a 10-digit phone number as an integer, but why would you want to? You CAN store a Social Security Number as a 9-digit number, but why would you want to? Surely you’re not so concerned of a few bytes savings. Storing an SSN of “0123456789” as a number means you use the leading zero, too, so you lose fidelity of data. Any string of digits follows this rule. You don’t perform calculations on part numbers, course numbers, Dewey Decimal numbers, or house numbers, either, so make ’em all character fields.

Same goes for years stored as date datatypes. If you’re recording the year that a movie was released, then there’s no advantage to having it as a date. Store it as an integer to make it simple to take differences (“How long after Citizen Kane did ET come out?”) or comparisons.

Most of all, keep things consistent. If you’ve got a 10-character column in one table, and an integer in another, then SQL joins will be very expensive, even if both columns are indexed.

Help the Perl Foundation choose a CRM system

January 12, 2008 Perl Foundation 1 comment

Jim Brandt, Conferences chair for The Perl Foundation, is looking for a customer relationship management package.

I’d really like to deploy a customer relationship management (CRM) package to allow us to better track our relationships with our donors, big and small. I was a bit surprised to turn up next to nothing when I typed “perl CRM” into Google.

Can you help? Read more of the story and reply at the TPF news blog.