What I like about perl

It keeps me warm at niiiight Is that it is very concise and expressive without telling me how things should be done. There’s no one true way in Perl as there are in some other more opinionated languages, it’s a pragmatic language that’s just trying to help you get things done – if you don’t want to work OO that’s fine with Perl, it won’t judge you.

It is well known that the non-Perl programming world loves to bash Perl. They can’t help it, it’s such an easy target. I don’t really want to talk about that here, I want this post to be about the love. Perl is really expressive – it is possible and quite easy to write beautiful concise Perl code to do a whole lot of work. I find code that is short, generally speaking, easier to understand than code that is long – if a block of code is viewable all at once, it is easier for me to understand all it’s moving parts. If the lines are short and there’s white space the code is easier to read. Is that just typography? I don’t know.

I’ve programmed many languages professionally in my time and a few more just for fun, C, C++, java, python, ruby, php, javascript – I even had to dust of the ol’ Wizard Book and bust out some scheme for one client. There’s no one true language, just whatever helps you get your job done faster, easier and more easily maintained. For me, that language tends to be Perl.

My love for Perl was reinforced recently while perusing the docs for the recently announced SimpleDB from Amazon. Going through their examples they provide code for Java, C#, PHP, VP.Net and thankfully, Perl. In keeping with the simple in the product name, many of these samples look almost identical.

But as you get to doing more interesting work, like putting in data, you start to see dense blocks of text in other languages and please seas of white space with Perl. It is incredibly easy to pull out the ItemName, DomainName and Attributes at a glance in Perl, where in the other languages you need to scan through all kinds of declarations and object creation syntax to see what is happening.

Everything in these examples are dead simple – very easy to understand. Perl just keeps it easier – eschewing all the extra syntax that other languages require. To me that helps everything.

Compare:

Java


String domainName = "MyStore";

String itemNameOne = "Item_01";
java.util.List<ReplaceableAttribute> attributeListOne = new ArrayList<ReplaceableAttribute>(7);

attributeListOne.add(new ReplaceableAttribute("Category", "Clothes", false));
attributeListOne.add(new ReplaceableAttribute("Subcategory", "Sweater", false));
attributeListOne.add(new ReplaceableAttribute("Name", "Cathair Sweater", false));
attributeListOne.add(new ReplaceableAttribute("Color", "Siamese", false));
attributeListOne.add(new ReplaceableAttribute("Size", "Small", false));
attributeListOne.add(new ReplaceableAttribute("Size", "Medium", false));
attributeListOne.add(new ReplaceableAttribute("Size", "Large", false));

PutAttributes putAttributesActionOne = new PutAttributes(domainName, itemNameOne, attributeListOne);

invokePutAttributes(service, putAttributesActionOne);

PHP


$domainName = 'MyStore';
$itemName = 'Item_01';
$attribute1 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute1->withName('Category')->withValue('Clothes');
$attribute2 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute2->withName('Subcategory')->withValue('Sweater');
$attribute3 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute3->withName('Name')->withValue('Cathair Sweater');
$attribute4 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute4->withName('Color')->withValue('Siamese');
$attribute5 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute5->withName('Size')->withValue('Small');
$attribute6 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute6->withName('Size')->withValue('Medium');
$attribute7 = new Amazon_SimpleDB_Model_ReplaceableAttribute();
$attribute7->withName('Size')->withValue('Large');
$attributeList = array($attribute1, $attribute2, $attribute3, $attribute4,
$attribute5, $attribute6, $attribute7);
$action = new Amazon_SimpleDB_Model_PutAttributes();
$action->withDomainName($domainName)->withItemName($itemName)->setAttribute
($attributeList);
invokePutAttributes($service, $action);

And of course… Perl

my $action = Amazon::SimpleDB::Model::PutAttributes->new({
ItemName => "Item_01",
DomainName=> "MyStore",
Attribute => [
{
Name => "Category",
Value => "Clothes"
},
{
Name => "Subcategory",
Value => "Sweater"
},
{
Name => "Name",
Value => "Cathair Sweater"
},
{
Name => "Color",
Value => "Siamese"
},
{
Name => "Size",
Value => "Small"
},
{
Name => "Size",
Value => "Medium"
},
{
Name => "Size",
Value => "Large"
}
],
});

invokePutAttributes($service, $action);

Again, not that any of them are not simple and easy to understand – but there seems a big difference in how much language you are overcoming in Java and PHP vs how much work you are doing. To me, the Perl version is doing the exact same work but is much cleaner and easier to take in at a glance. In the example there wordpress seems to have some difficultly displaying any indenting – but it’s there and makes it even more obvious, but even flattened it’s very very easy to see what all the attributes are instantly. As code gets more complex keeping things obvious like that becomes a great boon to maintainability.

Any how, it’s just a little observation that I thought was interesting going through those docs. No slight meant to other languages, I love you all. I just love Perl more. :) And big love to Amazon for keeping Perl in the loop there. The odd thing is that in all the docs for their various web services where language examples are made Perl is always one of them. Sadly, in their developer connection
they list Ruby (which generally does not show up in any of those examples) instead of Perl as a technology. Sigh. Perl hating continues.

blog comments powered by Disqus

Not Found

Sorry, but what you are looking for isn't here...