Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, January 8, 2009

Perl vs Python

Perl vs Python is a classic debate that has flared up on many forums, websites and user groups. Here is my $0.02 on the whole affair.

I was a very devoted Perl user till 2005 and then switched to Python, mainly because everyone else in the project was using it.

Like, so many others before me, I had difficulty getting used to the 'no bracket, indentation only' approach. But after some initial hiccups (mainly strong denial and prejudice against Python), I started writing some useful programs in Python. The indentation stopped bothering me after a while, but I never really bothered mastering Python the way I did Perl.

However, my opinion about Perl (and, indirectly, Python) changed last year. I had to generate some code coverage data for the Mac project I was working on but raw 'gcov' data files were not really helpful. I found that 'lcov' could create well formatted HTML pages showing code coverage data and annoted source code. I was very happy with lcov but going through lcov source code, written in Perl, left my head spinning.

I started losing track of the context within which certain variables were being used. The fact that I hadn't used Perl in while and had forgotten quite a lot of the idiosyncrasies native to the language did not help matters either. But I felt very guilty. I loved Perl before and I did not have any complaints against it earlier, so what happened now?

I went back to my old source code 'repository' (actually it was a bunch of zip files on a CD :-)) and had a look at the Perl code I had written. What was interesting was none of the scripts I wrote were more than 200 or so lines of code. They were effective but never long and I had never re-used any script. That made sense to me. I actually enjoyed using Perl as long as the scripts were small, I was the only one using them and I did not have to re-use them.

Henry Spencer, a well known computer programmer, called Perl a 'Swiss-Army Chainsaw, intending to convey his evaluation of the language as exceedingly powerful but ugly and noisy and prone to belch noxious fumes'. I think his observation is spot-on.

But once I started working with a team, Python seemed better. Python was a lot easier to read and understand and the learning curve was lot less steep. Python has everything that Perl offers but without the eccentricities. Moreover, Python has a better implementation of object orientation and is inherent to the language where as Perl's implementation has a very kludgy feel to it.

I will still use Perl for what it was originally intended for, mostly scripts that munge data, I will keep them small and will probably be the only one using it. I will, probably, use Python for everything else that is more involved and has complex tasks.

Update: I found this article, by Eric Raymond, which presents an argument in Python's favor more articulately.