Dabbling in Python and Perl

May 23, 2007

The past few months have given me the chance to explore both Python and Perl a bit. I’m using both languages to generate simple scripts, nothing web related yet. Since I’ve been working almost exclusively with Ruby for the past few years it’s been nice to get a different perspective when it comes to dynamic languages.

Python

First off, using whitespace instead of brackets or begin .. end didn’t bother me at all. People who dismiss Python because of the indentation rules need to get over themselves. I was also very impressed with the overall polish of the docs and libraries. Python definitely makes it easy to get things done, and never had to look hard for a library and documentation to accomplish a task. I especially appreciate that MySQLdb for Python emulates cursors in ways that I’d expect.

One of the things that bothered me was that Python can’t make up it’s mind when it comes to functions. Most string functions are Ruby style (i.e. “hello”.strip(‘ell’) ), but then there’s weird exceptions like len(). Why you would have len(“hello”) instead of “hello”.len() is beyond me.

Overall though I came away with a good impression of Python, and think Ruby could learn something from the quality of the documentation and libraries. I’m hoping this will come naturally as the Ruby community continues to grow.

Perl

I understand why people tend to rip apart Perl when given the chance. Yes, yes, I realize Perl has CPAN, and it has about every library under the sun, but I haven’t found it a good enough excuse to voluntarily use the language when given a choice. The syntax made my head hurt, and once I wrote more than a few hundred lines of code I found it hard to keep my train of thought as I worked through a program.

The one thing that struck me as odd about Perl, yet I kind of liked, what that for many of its functions it just used the syntax of many of its unix equivalents. If you know sed then you know how to do string replacement in Perl.

A Recommendation

Perl programmers, please, please move to Ruby. You will find yourself happier and with much more readable code. You will also get a language where object oriented features don’t feel tacked on and half finished.