Sharing Code with the Perl Community

I have been writing Perl for about two years now, and it has become one of my most useful tools. When I need to solve a problem quickly on the web, Perl is usually what I reach for. It is practical, it is fast to write, and there is an enormous community of people sharing their work.

That community is one of the things I like most about Perl. The Comprehensive Perl Archive Network, CPAN, is a collection of reusable Perl code that anyone can contribute to and anyone can use. If you need to do something with text, or files, or network connections, chances are somebody has already written a module for it and put it on CPAN. You install it, use it, and move on to the interesting part of your problem.

I recently registered as an author on CPAN under the ID BETUL. I have been sharing code in smaller ways for a while now. Last year I wrote a Perl script that determines the dimensions of a GIF image file, which I posted to a technical forum because I figured other people building web pages would need the same thing. I use Perl regularly at work at Philadelphia Newspapers for automating publishing tasks and building tools for the web sites. A lot of what I write there is specific to our systems, but some of it is general enough that other people could use it.

The idea behind CPAN is simple: if you solve a problem, share the solution. Do not make the next person solve it again from scratch. This is the same idea behind a lot of what happens on Usenet and the web. People post their code, other people improve it, and everybody benefits. I have used other people’s freely shared code to build things I could not have built alone, and I want to contribute back.

What I find interesting about this approach is that it works without anyone being in charge. Nobody tells you to share your code. There is no company managing CPAN. It is just a convention that Perl programmers have adopted because it makes sense. You write something useful, you upload it, and it becomes available to anyone in the world who needs it. The network handles distribution. The community handles quality through use and feedback.

I think this way of building software is going to become more common. The web makes it easy to share code across distances that would have made collaboration impossible a few years ago. I can write something in Philadelphia and someone in London or Bangalore can be using it the same day. That was not true when I started programming.

For now, I am focused on getting better at writing code that is clean enough and general enough to be useful to others. It is a different discipline than writing code that just needs to work for your own project. When you write for yourself, you can cut corners because you know the context. When you write for strangers, you have to think about what they do not know. That is a useful exercise even when the code never leaves your own machine.