I’ve got a new job and it’s working almost completely in Perl. Who’d have thought? Fortunately, it really is true that if you know one programming language fairly well, you’ll understand others fairly easily. Modifying code in Perl is easy as long as I have other code to refer to, and I often forget it’s a new language. Learning all the names, faces and practices in my new job is much harder than learning a bit of new syntax. However, if I had to sit down and write something in Perl from scratch it would not go well.

There’s definitely a few things I’ve noticed about Perl that I don’t like compared to Ruby:

* Sigils. I keep forgetting to prepend my variables with those $@% sigils. That’s not me cursing there, those are the sigils for scalars, arrays and hashes. The worst is when you’re references the whole array (@foo) you use a different sigil than when you’re referencing a scalar element in the array ($foo[0]).
* Objects feel like a hacked up addon to the language. You have to “bless” things to make them objects and you’re always passing around references to $self to object methods. You can’t make methods private. Weird stuff.
* No interactive shell built in. I loved having irb to try things out when I was learning Ruby – heck, I still do. Fortunately, after a bit of searching and bad advice on just using the Perl debugger I found Perl Console.
* Always needing to say “my variablename” instead of just “variablename” if I want local variables. It seems like variables should be local by default and you say something if you want to make them local.

There’s some things about Perl I’m not sure if I like or dislike yet:

* Default variables. Strangely named variables like $_ and @_ pop up everywhere. The idea is if you don’t want to come up with a name for variables while you’re iterating or passing parameters, you don’t have to thus saving all that typing and thinking. However it certainly makes the code harder to read for those who don’t know Perl and I suspect it might make things always harder to read even once I get used to it.
* Regular expressions everywhere. This will be good for me to get better with this powerful feature, but damned if regular expressions aren’t ugly.
* There’s always more than one way to do something. This is true in most every language, but Perl seems to take a lot of pride in it, and often the idiomatic Perl way of doing something is quite a bit harder to read than the non idiomatic way.

The main thing I like about Perl so far is that the Perl community seems to have a sense of humor. Perl books are always making jokes and variables in Perl code are given entertaining names.

Aside from the new language difference, the new job is great for me to get used to coding in a large codebase and with teams. We use quite a few Extreme Programming practices like test driven development, and even more impressive, pair coding. These practices more than make up for anything I don’t like about Perl.

2 Responses to “Programming Perl Instead of Ruby”

  1. Bryan says:

    I’ve been a C++ programmer all of my professional life but I’ve had to write Perl code for the past month. It has been…interesting. At times I’ve wanted to pull my hair out when trying to debug code. I’m having to implement software applications that are based on a giant Perl framework, and Perl software engineering is really an interesting concept.

    The following give me the most headaches with Perl code:
    * Having to put “1;” at the end of a perl module–it just feels very hackish, and it is easy to overlook or forget.
    * Fighting with accessing arrays when they’re stored in objects: do I need $self->{myarray}, or do I need @{self->{myarray}} here?
    * Exceptions thrown when comparing something to an undef object–Python just handles this more gracefully
    * There is no easy, one-step way to get a unique set of elements in a list/array.

    I agree with you about the Perl community, though, they seem to acknowledge the good and bad about this interesting tool. The Python community is quite smug about “the Python way,” but the Perl community is always happy to think about different ways to solve a problem.

  2. mattr says:

    The Perl community is definitely happy to think about different ways to solve a problem, I just wish sometimes when you ask the best way you didn’t get a different answer from every single person :-) Every language has its hackish feeling things that have been bolted on as the language matures, but yeah, Perl has more than it’s fair share of those. Hope your work in Perl proves productive.

Leave a Reply