Perl Before Swine

Have you used Perl? Did you enjoy it? You strange bastard. I have a very simple criteria when it comes to programming languages: if I can comprehend the code of something I did a year ago, then it’s a good programming language. I like maintainability and intuitive naming; it’s pretty hard to mistake what int or float means for example. I can return to 6502 Assembly, Pascal, x86 Assembly, C, C++, Ada, Lisp, 68k Assembly, Scheme, BlitzMax, Java, HTML, PHP and a dozen other languages long after I’ve stopped using them, and I still understand decently what I wrote ages ago. But not so with Perl. Perl is the devil’s plaything.

Okay, enough Perl bashing – it’s not really a bad language at all. It’s devilishly efficient at text manipulation and everything else involving regular expressions, for example. But I simply can’t remember Perl syntax; it’s like a black hole in my mind. Everything I pour into it that concerns Perl gets swallowed up. I can look at Perl code I wrote a few years ago and have no idea at all what it’s supposed to do! So I guess Perl is a little like pearls before swine in my case. Perl before Karja could be a new proverb.

Incidentally, did you know that the Japanese have a similar expression? Similar to pearls before swine that is. Neko ni koban apparently means gold coins to a cat. Not that I’d know – I just know what neko means. I think the most advanced Japanese phrase I can put together is watashi no soseji wa ookii desu yo!

Aanyhoo, the reason I started ranting about Perl is this excellent article I found called You Used Perl to Write WHAT? It shows five good reasons for when you should use Perl…and some situations where it’s just not appropriate at all. I don’t agree with everything. Take number 3 of the good reasons for example:

A replacement for shell scripts: One of the worst things about shell scripting—whether in bash, sh or csh—is that the syntax of the scripts themselves is fairly hard to read. By using perl as a scripting language instead of a “traditional” shell, you can use much more C-like syntax without sacrificing functionality.

I may or may not be biased but I find shell scripts infinitely more useful than Perl scripts. For one thing, they are more maintainable. Even though sed and strange syntaxes are black magic, it’s possible for another person to decipher what shell scripts are supposed to do. Unlike Perl, which is made for supernatural gods!

Finally I can end with an amusing anecdote. A friend of mine went to a job interview where they asked him if he’d ever written some Python. “Python… Oh! Yeah, sure – I know that!” So they gave him some code to modify, whereupon he stared blankly for a few seconds before he realized “Damn, it’s Perl I know – not Python! I’ve never seen a line of this before in my life!”

He got the job anyway. He was able to understand Python decently based on the examples, and had made a good impression during the rest of the interview. See what I mean about code readability? Could you understand how to construct a new regular expression after having looked at some Perl code?

Leave a Reply

Copyright © 2009 KarjaSoft