I am in the process of learning Python. It’s a very nice scripting language, but like any language, it has its own unique approach. That’s not lost on me who’s been a Perl nutcase for the last 17 years.
Perhaps the biggest issue surrounding Perl vs. Python (and perhaps Ruby) is this idea of the readability of code. Perl has been pigeonholed as a “write only” language. That is, you can write good Perl code, but no one else can read it. And neither can you, six months later.
In order to prove how bad Perl is, I have seen code on the Internet and — Heaven save them — at WWDC last summer where the speaker throws up some god-awful Perl code, perhaps pattern matching, to demonstrate the depravity of the language. Immediately after that, some very clean, equivalent Python code is displayed, leading the reader to conclude that the horrors of Perl are best avoided.
Of course, the speaker has an agenda, and that’s about what one would expect. In fact, any computer language, if mastered, is a powerful tool, and those with great mastery don’t worry much about such things.
For example, here’s some code I found on the Internet that purports to show how bad Perl is in “slurping” a file — and adds that Perl should be embarrassed. (Slurping is the art of reading a file as quickly and as simply as possible.)
local( *FH ) ; open( FH, $file ) or die "Problem\n" my $text = do { local( $/ ) ; } ;
Then that was compared to Python: “Mindlessly simple.”
fileContents = file("filename").read()
But then, no one I know of reads a file like that in Perl. The simplest slurp command in Perl is nice, indeed intuitive. Even Perl beginners, learn it right away.
@list = `cat filename`;
Another readability issue is this idea of variable prefixes. Perl distinguishes scalar variables from arrays and hashes (associative list, paired values in a list) with a prefix. So $a, @a and %a are different animals. In Python, variables are distinguished by how they’re initially set. That leads to a clean, “C-like” code, but Larry Wall, the father of Perl, will tell you that there are sound, almost linguistic, reasons for designing Perl that way.
Basically, those programmers who are susceptible to this kind of symbol shock will hate Perl and those who master Perl think nothing of it. I don’t.
There’s more to it than even that. There are some who argue that the readability of code is paramount because employees come and go. Maintenance is paramount. But readability is a function of a trained eye. Those who are beginner programmers will love Python for its clean syntax. On the other hand, should the readability of code for beginners be an attribute that defines the power of a language for grey-beard programmers with years of experience. I think not.
This is why I learn new languages and appreciate them for what they are without condemning the competition. I suspect that those people who have the strongest, emotional attachments to a language, simply have a psychological preference for one way of doing things — and they don’t have the experience or introspection to appreciate the nuances of multiple languages. So they wail, and viciously condemn alternatives.
The same war continues between Java and C++, text editors, computer operating systems, vacation spots, football teams, you name it.
My own motivation is to learn how to write Cocoa apps with Python via the Cocoa bridge instead of Objective-C, not because I don’t like Obj-C, but because I think Python is a language that has more career potential, and I’ve always wanted to learn it. I think scripting languages like Groovy, Ruby, Python and Perl are cool. I’d love to learn them all.
Calmly, with curiosity, admiration, scholarship and no bad attitudes, I hope to do so.