Got a list of bullet points as to why Python is better

So Tyler says to me, he says:

I went to the Nashville PHP group last night. The conversation turned to which languages are on the rise, and I threw Python into the mix. Problem is, I had very little ammo to arm myself with. Got a list of bullet points as to why Python is better?

Well, yes and no.

In terms of functionality, there’s very little difference between Perl 5, Python, PHP and Ruby. The reasons to choose one over the other are typically very domain-specific (hence subtle and of little use when fighting religious wars): Perl 5 makes text munging simple by having, e.g., regular expressions as first-class citizens; PHP makes web applications more natural because, well, that’s what it was designed to do.

I have nothing really positive (or negative) to say about Ruby. I can’t think of any special niche that it fills. Anonymous blocks? Perl 5 has them. Pure OO? Python has it. call/cc? If you think you need continuations, you probably don’t. You could argue that Ruby serves a purpose by combining all these things, but the number of people who sincerely need a pure OO language with anonymous blocks and continuations is probably around five.

The negative things I can think of with respect to Perl 5 and PHP is that it’s hard to do dependency injection-based testing in these languages. It’s so hard in Java, for example, even Google has invented a tool to make Java DI easier. Python on the other hand makes this dead-simple, making it so much easier to test your code from all perspectives. Hell, it’s so easy in Python, I didn’t even know there was a name for it until I came to Google. I don’t know how easy DI is in Ruby, but if it’s not Python-easy, Ruby loses.

That’s one criterion for programming languages that I don’t see discussed much: ranking languages by how easy the code is to test. One frequent example is mocking a global resource like a time source. C, C++ and Java all require you to come up with unnatural function signatures or link against special libraries when testing in order to gain control over time. It’s easier in Perl 5, but it still requires a good deal of specialized knowledge of how namespaces and module lookups work. Assuming the target library does something like import time at the top, here’s how you take control of a given module’s time source in Python:

>>> import some_module
>>> class StubTime:
>>> def time(self):
>>> return 3634634
>>> some_module.time = StubTime()

Done. No specialized knowledge of interpreter details, no crazy setup, just done. If mocking global resources isn’t that easy in PHP, Ruby or any other language, I have little use for it beyond toy projects. Testing is where I feel Python really stands out.

Talking Popfly

I mean, seriously.

Popfly is the fun, easy way to build and share mashups, gadgets, Web pages, and applications. Popfly consists of two parts:

Popfly Creator is a set of online visual tools for building Web pages and mashups.

Popfly Space is an online community of creators where you can host, share, rate, comment and even remix creations from other Popfly users.

“From the same team that brought you Internet Explorer, it’s…Microsoft InternetWeb 2.0!” You know, I wish I had a monopoly to free me from the pressures of innovation, the need to be fresh and creative, secure in the knowledge that no matter what mediocre, uninteresting crap I pushed out, it would still be foisted upon millions against their will.

At least they admit they’re uncreative: “left to our own devices we would have called [it] ‘Microsoft Visual Mashup Creator Express, May 2007 Community Tech Preview Internet Edition,’ but instead we asked some folks for help and they suggested some cool names and we all liked Popfly.” Maybe you should have asked those same folks whether a “Visual Mashup Creator” was even a good idea to begin with. My hunch: “um no”.

I can’t imagine why anyone would want to work for these people. Popfly is the kind of product that happens when upper management says, “Hey, we have to show our shareholders that we’re doing this Web 2.0 thing they keep hearing about!” What a sad, sad little company.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.