Archive for the ‘python’ Category

Michael Tsai - Blog - Perl vs. Python vs. Ruby

2008/05/26/0313

RTFA: http://mjtsai.com/blog/2002/11/25/perl_vs_python_v…

I’m evaluating Python and Ruby as replacements for Perl. I’ve been using Perl for several years and am very comfortable with it, although I’m definitely not an expert. Perl is a powerful language, but I think it’s ugly and encourages writing bad code, so I want to get rid of it. Python and Ruby both come with Mac OS X 10.2, both have BBEdit language modules, and both promise a cleaner approach to scripting. Over the past few weeks I read the Python Tutorial and the non-reference parts of Programming Ruby, however as of this afternoon I’d not written any Python or Ruby code yet.

Here’s a toy problem I wanted to solve. eSellerate gives me a tab-delimited file containing information about the people who bought my shareware. I wanted a script to extract from this file the e-mail addresses of people who asked to be contacted when I release the new versions of the products.

The real gem in this post is the 6-year-old comment thread, where a ton of people have posted versions of the same program in Perl, Python, and Ruby.

Here’s what I have to say: I use Perl5, and it is a natural extension of Unix. Most tasks that I would write in bash are easier to debug and maintain if I do them in Perl. I tend to write wrapper functions for pretty small units of computation, giving them names like “generate_total_from_invoice”, and as a result my Perl code tends to read like English.

Right now, though, I’m looking to write a scalable, maintainable object-oriented project… and I’ve been burned by Perl in the past for this task. It’s sick, but I long for Java’s strict typechecking, abstract interfaces, class properties with inheritance… I am really excited about Moose and Coat, but since they won’t be part of the base language until Perl6, it means most CPAN modules don’t take advantage of a sane OO interface.

Python happens to be really mature by this point, and the community is clearly vibrant. I have seen some really interesting stuff in the web app space, and it looks like Python provides third-party libraries that are comparable to CPAN. The importance of having a community of third-party library developers can’t be stated strongly enough, because it is through CPAN that I have gained great efficiencies by reusing other people’s code.

I think Python OO code looks great - I love the syntax, because it’s absolutely clear how class inheritance works. I think Ruby looks great too, but I think the community is too young and their libraries are too alpha. The Rails community is really exciting, however, and it obviously has a lot of momentum. I don’t like the idea of switching to ActiveRecord for data storage, which seems to be emblematic of a general trend in the Rails community to dictate “the right way.” Of course, I’ve seen some terrible Perl code (mostly my own) and the power to write the same thing in more than one way can burn you… but many times, “the right way” isn’t flexible enough.

In my humble opinion, I will conclude that RIGHT NOW, I think the most attractive language is Python. The bottom line is that any of these three languages will get the job done. Perl5 has a MAJOR problem with OO, and Ruby has a minor problem with the age of its community. I’m really excited for Perl6, because I have seen the future of Perl OO and I completely support it. However, I’m also a little scared to see what happens to the Perl community when the 5-to-6 switch happens (if it ever does). Really, Perl5 OO should be considered to be broken, and Perl6 is a completely necessary improvement.

…but if I’m not mistaken, Perl6 syntax is strangely dynamic to the point that it will essentially be a superset of Perl5, Python and Ruby… and Perl will again be the postmodern language to create a new paradigm for the next decade. IMO Ruby looks the nicest, and Perl is the “best” when you include the community, but Python has it all. Doh!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] Sphere: Related Content