28 September 2004

Why Perl rocks

One of the reasons I like Perl so much was brilliantly explained in a recent article on LinuxWorld. He uses a restaurant service analogy to explain how Java has been "destroyed by rampaging computer science":

Imagine if the Perl cafe and Javahut were across the street from each other. You walk into Javahut, and ask to sit down. "I'm sorry," says the person at the door. I'm not actually the hostess, I'm a Factory class that can give you a hostess if you tell me what type of seat you want." You say you want a non-smoking seat, and the person calls over a NonSmokingSeatHostess. The hostess takes you to your seat, and asks if you'll want breakfast, lunch, or dinner. You say lunch, and she beckons a LunchWaitress. The LunchWaitress takes your order, brings over your food, but there's no plates to put it on because you forgot to get a CutleryFactory and invoke getPlates, so the Waitress throws a null pointer exception and you get thrown out of the place.

Perl is one of the few languages where you can write what you mean without getting bogged down in details of unnecessary abstractions, privacy and protection. Of course there's a downside to taking this approach, if you're building an enterprise system. But for the type of day-to-day uses you want a programming language to help you with, dealing with huge libraries to perform simple tasks is just annoying.

Another common misunderstanding is that Perl only runs on Unix systems. Actually, ActiveState have had a Windows version of Perl for many years. Perl has many Windows-specific libraries, and can integrate with many applications.

These two facts let me use Perl frequently on my desktop machine at work. For example, I use the tools functionality of my favourite text editor to generate SQL and other code in Perl. The benefits in quality (fewer typos) and speed are enormous.