Perl versus Python

I am used to program Perl for years now. Although I have seen a lot of Perl code from other people that is really unbelievably ugly I still think that Perl is my language. But it is not a clear winner for everyone. These are my thoughts after trying to learn Python:

Perl pros

Perl cons

Python pros

Python cons

Opinionated

If I were asked to sum up my opinion of Perl versus Python I would put it like this: Perl may be about hacking together ugly code pieces if you are not careful but it has tools for every task you will ever need. Python is beautiful but incomplete. Perl is funky but practical.

Python is a very pretty language which makes code maintenance a bit easier on large projects. Still it is not magical and reading other people's code can be as weird in Python as it is in Perl. Python scripts do not look well if you do not document your work or use decent naming of variables and subroutines.

I tried to get an idea from other people's web sites whether Python is better than Perl and why. Actually most of those sites are bashing Perl. Mainly because the authors are unwilling to really learn Perl. There are reports where "experienced perl programmers" started with Python from scratch and one our later had solved a complex programming problem. Bullshit! There is good documentation on Python for starters. But it will keep you busy for at least an evening if you are really fast-paced. You need to understand the syntax and concepts before you can really start doing more than a print "Hello, world".

Python's syntax is easier than Perl's. Python provides syntax for programming tasks that often reoccur. Perl programmers merely find hacks and workarounds for Perl's syntactical flaws. Yes, Perl can handle all kinds of tasks. But it is not always clear from the source code what the programmer wants to accomplish.

When I explain my Perl code to others I find myself explaining why I did this and that because it is less obvious. Although I have not worked much with Python in a team yet I believe that there are fewer moments when I shrug because I cannot figure out why I did certain code passages. Perl sometimes is black magic but Python does not have that taste of mystery. There is seldom more than one way to do it in Python so if you are a source code artist you may find Python boring. Perl's often quoted TIMTOWTDI (there is more than one way to do it) often results in: there is no obviously right way to do it. Honestly: I like my Perl scripts. I have been programming Perl for years and with decent style (mainly using abstraction through classes) even large projects were maintainable. I also found it interesting to see other people do the same task in even fewer lines. But every nifty hack turned out to be boomerang because the niftier it was the worse I could understand it a few weeks later.

FWIW Python makes the simple tasks look good where Perl often uses less intuitive syntax. However using both languages for real life tasks both languages quickly can become ugly if you don't know the languages well. Comparing the Perl Cookbook and the Python Cookbook I definitely consider the Python hacks more ugly. And since Perl has a larger library of well documented modules it is mainly my language of choice currently. I have tried to get into Python time and again but the real life has often hit me.

My conclusion? If you are new to programming: start with Python. If you are an averagely experienced programmer and need to solve a task in team work you should try to get it done in Python - even you have no Python experience yet. Just calculate that you may reinvent features that you are used to use in Perl.

If you - like me - have been working with Perl for years then you will hardly find Python so sexy that you will instantly switch over to Python. Perhaps you should take the Python tutorial Dive into Python and just read how things are done in Python without thinking too much about where you will end. If I am in a hurry I will likely hack something together in Perl. Though on larger projects where I have more time to accomplish my goal I will likely try to do it in Python and get some practice.

Links

WorkaroundOrg: PerlVersusPython (last edited 2005-08-24 20:17:18 by ChristophHaas)