Why Python?

A reader1 asks:

It seems like everywhere I look people are pushing the Ruby programming language… What reasons are you using Python? Is it because of certain characteristics of the language itself or because you are more familiar with it (due to coming from a Perl background)?

A fair question, and I’m going to pretend that my answer is worth knowing.

Ruby is the it scripting language and has been since Rails came out several years ago. I’ve tried it in the past and—mainly because of MacRuby—will probably try it again. But there are things about Ruby that set my teeth on edge.

First, though, the titular question: why do I use Python? I can’t say my reasons for switching from Perl were entirely rational, but it was some combination of:

  1. The feeling that Perl 5 was a dead end (that had an awful object syntax) but that Perl 6 would never come online. The years have proved me right about Perl 6. Perl 5 isn’t the dead end I thought it would be, but it isn’t the vibrant language it was in the 90s, either.
  2. The no braces, no semicolons, no begin/end syntax. I think the people who hate Python’s use of indentation to denote structure are nuts. Unless you’re writing one-liners, you’re going to use indentation—why not take advantage of that to get rid of all the nonfunctional characters?
  3. The “batteries included” philosophy of the standard Python distribution. There’s seldom a question of which library to use; you use the one that came with Python.
  4. The NumPy package and the adoption of Python by many scientists and engineers. This turned out to be a false reason, as I’ve never used NumPy. But when I was thinking about which language to switch to, NumPy and SciPy were pluses for Python.
  5. The from __future__ import division statement. This seems really stupid, but I hate when a scripting language tells me that 1/2 is zero instead of 0.5. I suppose this comes from my being an engineer instead of a programmer; I almost never use integer arithmetic and don’t like it when I have to think about how my language is going to interpret a simple division. In fact, I tried Python a couple of times in the 90s—before the __future__ module—and gave up because integer division mistakes were so frustrating. I was happy to see that Guido recognized his initial mistake and made floating point division the default in Python 3.

Items 2 and 3 (and yes, 5) are why I still use Python.

What annoys me about Ruby? Small things, mostly, some silly, some substantive:

  1. Integer division, obviously. That Ruby uses it seems especially odd to me, because Ruby is obviously and outgrowth of Perl, which uses floating point division. This is a case of Matz not learning from Larry Wall’s example.
  2. That include and require sound like they should do the same thing. I know that if I used Ruby enough, I’d learn the difference (and probably just use require 99% of the time), but the seeming similarity bothers me.
  3. The ever-changing notion of the “right” way to do things. Maybe this is just the ignorance of an outsider, but it seems to me that Ruby best practices are a fast-moving target. For example, I get that the gem system is the standard way to install modules, but I don’t see how a newcomer to the language is supposed to know whether require 'rubygems' is a good idea or not.
  4. The accretion of tools built upon tools. This is similar to my previous complaint. When I read about some clever Ruby library/utility that I might consider using, the installation instructions often refer to gem or rake or rmv or some other add-on. I appreciate that experienced, expert Rubyists can get a lot of leverage out of these tools, but they’re a barrier to entry for newcomers.

I know the solution to my problems with Ruby is to just dive in and start bulling my way through—the best way to learn a new system is to just keep using it. So far, though, I just haven’t had the need to stick with Ruby long enough to get comfortable. This is going to change. There once was a time when I thought PyObjC would let me write Mac-like programs in Python, but it’s clear now that MacRuby is the better choice. I need to expand.


One Response to “Why Python?”

  1. Clark says:

    The big limit with Python (which is my language of choice) is threads. It just really doesn’t do true concurrancy. Not a big deal now, but perhaps in the future. (Does Python3 fix this?)

    Yes Rails is big in Ruby but I’m told Django is pretty nice too. (I’ve only done rudimentary stuff with it)

    PyObjC didn’t really pan out. I use it occasionally. However it seems like I really need to use Obj-C and Cocoa a while to make it worth it. And at that point why not just do it in Obj-C? I suspect MacRuby is much better than Python + PyObjC however it still has that problem that you really need to be familiar with Cocoa and Obj-C such that it kind of defeats the purpose. There’s also just not enough sample code and documentation out there (IMO).

    My sense is that Ruby and Python are pretty similar and which one you prefer is more a function of either which one you tried first or which project you ended up working on.