I Don’t Like Perl

The transition is complete. I am now a full blown Python weenie. I’ve recently had cause to write some Perl, something I haven’t done in several years and I’ve come to the conclusion that Perl is ugly. Once upon a time I was a Perl weenie. I relished in the freedom and flexibility that Perl gave me compared to the difficulty of implementing complex data structures in shell and the lack of portability of compiled C or C++. I could do magical things with Perl. I could parse and print with power and flexibility that had seemed an impossible dream. I could extract obscure mail statistics from the arcane log entries of sendmail. I could write CGI scripts.

I also remember struggling with how to implement hashes of arrays, or hashes of hashes. I remember scratching my head as I tried to intuit which context I should be in when asking for my data back. I knew I’d put in it the container, though I wasn’t quite sure what the container was. I knew I had to ask politely for my data back, but I wasn’t sure if I should be saying Please or Por Favor. What I was trying to do wasn’t simple, after all, so it was only right that it should be a challenge to get the code right. I remember going back to that program after six months and having to struggle with the same things because I wanted to change the program.

Recently I once again had to re-learn aspects of Perl that had been replaced with more Pythonic information. How exactly do you implement a dictionary in Perl again? I seem to remember # characters. Or was it @’s? I had to read other people’s code, interpreting single character variables, inline print statements and => syntax. Oh yes, and the brackets. So many brackets.

After this wrestling I have come to agree with those who disparage Perl by saying that it is a write-only language. It has a wealth of modules that connect it to databases, the web, XML and all the modern cool stuff. It has inbuilt =pod documentation. It has reference material aplenty. It is also ugly. While it is possible to write nicely readable Perl, it takes work, work that many hackers simply do not take the time to do. I have been guilty of this, too, since in Perl it is just so easy to fire off a single line of if (( $# => ‘doing’ )) { print } $and (@some) {$#other} ‘stuff’ + “\n”;

Yuck.

It is possible to write ugly Python. It is possible to write complex and confusing code. I’m looking at you ZopeCMF 2.x, aided and abetted by Twisted on occasion. Even at its worst, you can find your way through the seemingly endless Tracebacks to find out what’s going on with reasonably helpful default error messages. You can read the code more easily because of all the whitespace and fewer brackets. I can go back to code I wrote six months ago and not spend a couple of hours wondering what I was trying to achieve.

Much of this is due to a level of maturity and ability that is only gained from years of practicing your craft. You have to make mistakes, and learn from them, over an extended period of time to truly understand why comments are so important, and what sort of comments are best. You learn what level of modularity is required, that too much can be just as bad as not enough. You learn that even ordinarily great code will contain islands of poorly commented and obscure algorithms. You will gnash your teeth in frustration at the colleague responsible, but you will be able to figure things out.

After reading some Perl (specifically: tv_grab_au) today I realised that the reason I don’t like Perl is the same reason I don’t like the islands of poor coding that I sometimes come across: it’s a jarring experience. When you’re used to sailing smoothly along, coding  productively in the sunshine, it’s upsetting to have a cold wind blow up out of nowhere and set your boat to rocking. I am so used to the smooth sailing of Python that to be forced to use Perl is frustrating and annoying.

Programming language choice can be a highly personal thing, so I don’t want to get started on a language war here. I’m simply trying to explain how my personal choice of preferred language has come about. Nowadays the features of both languages are fairly comparable, and though CPAN still beats Python for sheer volume, Python doesn’t need 19 implementations of logging. The greatest advantage that Perl enjoys is that it comes installed on virtually every unix OS available. You are unlikely to find Python on Solaris or HP-UX, but the odds are good that you’ll find at least Perl 5.6. I long for the day when Python 2.3 or .4 is also available as standard.

Until then I’ll have to continue wrestling with the occasional piece of Perl while doing my own work in Python where I can.

Bookmark the permalink.

Comments are closed.