Perl vs Python: Why the debate is meaningless
Competition is a common thing is hackerdom, and arguments over which one of two (or more things) is the better are common and keep coming and going (but never really go away). Some of the most common ones are: Java vs C#, Emacs vs Vi (and it’s clones), Linux vs BSD, Closed Source vs Open Source and everyone’s favorite: Microsoft vs everyone else. And the internet is littered with evidence of these great wars (which none too rarely take on epic proportions) and some digging will throw up evidence on forums, website, bulletin boards, Usenet archives and of course, blogs. Today I’m taking a look at one of these wars that I’ve had personal experience with: Python vs Perl.
The last few years of my life have been filled with an as yet unfulfilled to learn some real programming (see last post). A few months ago I sat down to really learn Python, because I had a read a lot online about how it is a great beginner’s language (though I’m not really a complete newbie at this point). Anyway, I’ve been at it for a while and I’m liking how things are going.
But before I had started Python, I had a brief brush with Perl a year ago. At first glance it seemed something I had dreamed of. After struggling through memory management in C++ and Java and sitting through long compile times (which are really irritating if you’re a new programmer making lots of mistakes), Perl’s write and run was a dream and built in memory management made me a lot happier. But it didn’t take too long for me to get dissatisfied. Reading other people’s code was never very easy and variables behaving differently in different contexts was not something that I liked. I left Perl in just over a month.
Looking for an alternative I quickly found out about the Python vs Perl debate and was especially inspired by Eric Raymond’s Linux Journal article. I started Python and quickly fell in love with it. It had all the things I liked in Perl, but none of the eccentricities that I had wanted to leave behind. For a long term I didn’t give Perl another thought. But being the avid netizen, open source fan and linux lover, I kept reading about Perl here and there. So, last December, I decided to look into Perl again.
What I found out since then is that the Perl vs Python debate is rather like apples vs oranges. One of the biggest complaints about Perl is that it is untidy. Perl’s philosophy of “There’s More Than One Way To Do It” means that there are numerous ways to twist your code syntax around and it can be made absolutely unreadable. And it’s not just the syntax. Perl’s later features, especially object-orientation, have a distinctly kludge-like feel about them, as if they were simply slapped on later rather than integrated. Python, on the other is much cleaner and better designed. But there’s a twist to this tale. It’s this: Perl and are Python are very different languages.
Firstly Perl was not meant to be a general purpose language. It was meant to be a sort of shell-script on steroids. It’s a glue language, aptly called a Swiss Army Chainsaw. If you have a myriad of different programs and data sources and all you need to do is bind them with the electronic equivalent of duct tape, use Perl. Keeping Perl to it’s original uses makes most of the problems disappear. You don’t come into contact the kludginess of more advanced features because you will rarely (if ever) use them and readability isn’t so big a problem, because your programs will not genrally be more than a hundred or two lines.
Python on the other hand, is a more general purpose language. Features like object orientation are better implemented because you’re expected to use them all the time. And there is a definite emphasis on writing clean code because your programs will be big with complex tasks, not just delegating to other programs.
So the final word is this: choose your tools carefully. If you need something that will update a web page with a list of recently played songs, use Perl. A good example of how to use Perl effectively would be Xterminus’ changes page, which uses a Perl script to gather data from his del.icio.us account and his wiki software and create a pure HTML page. If you want to write anything with more than a few layers of abstraction and of more than medium complexity, grab Python. If you have any experience with these two, let me know.
Tomorrow’s debate: Emacs vs Vi
Update: I had said above that I found memory management in Java and C++ tedious, I admit that was something of a typo. I hadn’t meant to say just C++. Thanks to Digg and Reddit users for pointing this out.

You seem to suggest that different tasks conveniently/necessarily require different languages, but sticking to one language (a single syntax) often brings more power to the programmer. This also facilitates resue.
Unfortunately your limited time with perl shows.
There are established best practices that make Perl code very readable and easy to maintain.
What’s up with those no-brackets-indentation-only approach huh? Doesn’t that make your head spin?
I’m not saying that Perl is the best and that all other languages are useless. I believe every language has it’s strengths and weaknesses. But most of the time Perl’s strengths are greatly underestimated and it’s weaknesses overstated.
I mean in Python (the indentation-only approach)…
I’ve write code in C, Java, Perl and Python. In all of them, if you want your code to be readable, you have to indent (except for python, you’re not required to). So the brackets are useless, since every language encourages the indentation. If you want to bracket python, simple do it with the help of the comment symbol #. Easy.
while(True): #{
doSomething #;
To the Perl aff(licted|ianados):
You are defending a scripting language with *pointers*.
If I want to use pointers I will use C, thanks very much.
[...] http://xcomputers.wordpress.com/2007/01/…; - Perl vs Python… a meaningless debate blog. [...]
I don’t know Python but I can comment on Perl. I have written many elegant scripts for complex problems and I still love it. I often come across comments about how a programmer went back to his program six months later and had difficulty understanding it. For my part, I haven’t had this problem primarily because I use consistently a single syntax. If perl provides more than one way to do things, I choose and use only one. Secondly, I do agree that objects in perl are clunky and make for difficult writing/reading. I have never used them. This makes it difficult for me to write perl scripts for large projects. Perhaps this is where Python succeeds.
Perl vs Phyton
Since my new job required Perl i also plumbed into this we discussion. I wondered should that job be done with Perl..
I agree one might be able to read his own code back.
But have you ever tried to repair or code from other people or add some extra functionality. I gues that’s a perl nightmare.
Dont get me wrong i’ve used many languages from a beginning to novice degree and some expert, to give you an idea: Basic, Qbasic, Phython, Pascal (several versions), C++,C# plain C VB6 VB.net Kixstart VBscript and some others.
My first impression of Perl, it’s like Kixstart and verry old Basic (without MS in front). Kixx a cutom shell language, and basic well it can deal with vars but in a bit $poor way.
Looking at phyton i see a some good editors and a much more clean language.
Notice that a final compiler doesnt compile spaces (..duh).
Spaces are for readability.
Other people will be able to read someone else his phyton, and understand it i’m sure. I dont believe this for perl to be treu.
That doesnt make Perl a hardcore type cool language, it’s making it an old language. Computer Languages evolve
In the end it doesnt make a big difference how you get things done, if you only wanted to get them done, but there is more..
You see I’ve also did assembler once. And could get things done with it but does that code fast / or is it easy to repair to maintain ?
Nope.. old languages are just not cool. You can stay with it but the next generation people will slam you.
Old languages can be full of tricks (like kixx and perl) but are poor in meaning of the word “language”
Sadly i was also just looking into VB.net en C.net again (new version), if you would compare those languages to perl of phyton then you see a huge difference in well first syntax but next support click a unknown verb and get forward to MSDN online help with samples and comments that must be magic to perl/phyton people.
Serious programmers no they should once in a while look around to other languages.. that might be something for perl-scripters to get started to think about a language.
I wish there was a perl.net
you see even MS was abele to make Basic o-o
I was forced to learn Python in order to write scripts within Blender (Open Source 3D Modeler).
White Hat:
1. dir( object )
This is nice as it shows functions and constants.
Black Hat:
1. Indention to denote code blocks. (!caca?)
PERL was more of an experiment instead of necessity. Much of what I know about regular expressions probably came from reading about PERL. I never even wrote much code in PERL. You see CPAN (Repository for modules) alone makes up for all the drawbacks I can’t think of at the moment.
White Hat:
FreeBSD use to extensively use PERL for installation routines (4.7., I keep a copy of it in my music case although I don’t know why as I feel its a good luck charm of sorts). Then I read in 5.0 they started removing it in favor of shell script (BAsh). Why?
Black Hat:
I’m drawing a blank here.
With freedom there are costs, you are alowed to do as you please. Place variables as you must and toss code a-muck.
You can dislipline yourself to write great code in any language. VB-Script I write has the apperance of a stardard practices C application.
I think it’s a waste of time to sit and debate over which language is suited for which project. Pick one and master it.
So you can’t read PERL? Break the modules into several files. It’s more about information management than artisan ablility. Divide and Conquor.
^
It’s Perl, or perl.
Not PERL.