My first Perl module reverse-engineered a proprietary network protocol used at the company I worked for at the time. My purpose in creating it was to test the production and development implementations of the protocol. The module quickly grew to over 1,000 lines of code. I developed a sense of dread every time I had to make even the slightest modification to this particular module. After a while, I couldn’t take it any more. I needed a language with cleaner OO support. That’s when I found Python. And I have used Python nearly exclusively ever since.

What was so painful about that Perl module? The first thing was my newness to OO…and to programming in general. At that point, I had done some C and shell and was still pretty new to Perl. The majority of my OO exposure was what I had read in the perltoot.

The next thing was the general oddness that went into creating a Perl module. For example, there was this “bless()” function. I didn’t get that. What was “bless()” and why was I doing it to my “$self”? Another weird thing was the “1″ at the end of my module. I didn’t get that, either. But, neither of these things were deal breakers for me.

The next, and probably more significant, thing was dealing with complex data structures such as a hash of hashes. At the time, all those curly braces and arrows and backslashes were just not intuitive to me for creating the data structures that I needed. And I had even read perldsc.

I’ll go ahead and admit it. The problems I had with Perl says more about me and my understanding of Perl (and programming) at the time than it does Perl. I was a newbie trying to do something that was fairly complex with a language which will gladly give you plenty of rope to do with as you please. I happened to be putting that rope rather uncomfortably around my neck. At least that’s how it felt at the time.

I was reading Perl Testing by Ian Langworth and chromatic the other day and had a moment of enlightenment regarding Perl and OO. One of the example pieces of code was a simple OO module. As I was reading the code, something about it was comfortably familiar. The constructor (typically “new”) returned a reference to itself (typically “$self”). That vaguely reminded me of the __new__ method in Python. “$self ” was a hash, which reminded me of an object’s __dict__ attribute in Python. Each method’s first argument was an implicit “$self”, which is pretty much identical to Python.

I still prefer the Python syntax over the Perl syntax, but I feel that my exposure to Python helps me “get” what Perl is doing with its OO implementation. Funny. I feel like I could probably do some Perl coding again and not mind it so much…even before Perl 6 is actually released. So, I don’t consider Perl’s OO evil (any longer). And I don’t consider OO to be so bolted on as an afterthought (which it might be…I really don’t know). And, even though it appears as such at first glance, I’m not so sure that the internals to OO are any more exposed in Perl than they are in Python; they’re just more Perlish.

The “take away” from this little stroll down nostalgia lane is that Perl isn’t so evil. And specifically, its OO support is usable. I still prefer Python, but Perl is a viable language for getting work done.