Reusability: The puzzle of perl

I write a lot in perl. But I’m not really good at it. I neither know how to do error handling nor objects nor user-interfaces in it (something I at least know how to in C++ and VB).

I think this describes a lot of perl users.

The thing with perl is reusability. Perl is the first and only language that has actually been able to produce high-level reusable components.

I can go to CPAN and get a module that screenscrapes html with support for forms, cookies and navigation (so I can make a program that goes to a library site that uses sessions, tell it to but an ISBN in the isbn field, press the submit button, follow the link in the following page and extract the MARC from that comes).

I can go to CPAN and a get a module that parses MIME-encoded e-mail messages and write my own e-mail virus-checker in 400 lines (most of which is taken up by the human-readable messages).

I can go to CPAN and get a module that allows me to upload pictures to flickr, update them, and retrieve comments from it.

And of course I can go to CPAN, and get interfaces for any database you can name, to read and write XML, to build cgi-bin programs, to talk any network protocol from Jabber to http to FTP to NTP, compress and uncompress streams or files and parse or write file formats
like GPX or SVG.

And of course all of this works on OS X, Linux, Win32 and anything else you can imagine with the same code.

I don’t think anybody really knows why Perl and CPAN have succeeded where everybody else with, on the surface at least, better languages and environments have failed miserably.

It might be a really clever idea to try to find out. Depending on your tastes, there’s probably either a PhD or a company in there.

There are of course several things that we can hypothesize have influenced this:

  • It’s really easy to install something from CPAN. You need component X? Just fire up the CPAN shell and say ‘install X’. It’ll fetch all the dependencies, build, test and install it including documentation.
  • Because the code is portable to many platforms, you have a much larger potential group of contributors.
  • Perl has only a few ‘real’ datatypes (scalars, arrays, hashes and references). Objects are just hashes. This means that whatever interface foo returns is probably either directly usable with
    interface bar or convertible with a couple of lines of code. Compare this to C++, where if you have an object of class baz, the only way to get an object of class quuz out of it
    is to write a property-by-property conversion routine. Small impendance mismatch.
  • A culture of testing. The code that you get from CPAN will have a test-suite, and it will probably work quite well.

But I don’t think this really explains it all.

This entry was posted in CS. Bookmark the permalink.

One Response to Reusability: The puzzle of perl

  1. John Bokma says:

    “Objects are just hashes.”

    Objects are blessed references. The reference can be to a hash, but that is not needed.

    Good article, CPAN is indeed what makes Perl so good.