Why I like Python

Schwuk makes reference to a post of Rory’s on why Python is no good. As Schwuk says, I might get annoyed by this, and he’s pretty much correct here.

You see, I think that a reasonable proportion of Rory’s complaints are a bit lacking. Take his complaint that you have to explicitly pass “self” to methods:

Sure, having to add self to a parameter list once isn’t any big deal, but three-hundred methods later, when the ink is worn off the S, E, L, and F keys, you might be thinking differently about it.

Take a glance at your close-curly-bracket key: }. Has the ink worn off that? If it has, then I’ll start to listen to your complaint more. If it hasn’t then, well, obviously extra unneeded characters, like C’s curly brackets, aren’t that big a deal, eh?

I would have respected a choice to have ditched all 1.x hacks, but instead they were carried over to 2.x, so now we had the choice of doing things procedurally or Object Orientedally (yeah – I made that word up – bite me). What a bloody mess! Let’s see… Do I want to work with functions on my strings, or do I want to work with members of the string object? I hate that kind of crap.

I utterly don’t agree here. OO gives you the power to write decent proper applications; I entirely agree, and I pretty much find that anyone writing anything even vaguely substantial in Python uses OO to do it. But constricting the user to write in OO style is a massive pain in the arse when you just want to throw out a quick script. I find myself doing things like

grep "some regexp" /some/file | 
python -c "import sys;print 'n'.join([x.split()[3] for x in sys.stdin.readlines if x.split()[6] == 'word'])"

If I had to wrap that in a load of OO bullshit it’d be loads more complex for no reason. Similarly, a lot of the Python I write is short scripts to, say, grab an RSS feed and rip some data out of it (the thing that reposts my SitePoint articles here is like that). Again, this is a quick procedural script: start at the top and work through the lines. They quite often don’t even use functions. If I had to swaddle that in OO bollocks it’d be more complex and slower to write and I would derive no benefit from it.

Notate bene primus: Perl people are saying “what’s all that sys.stdin.readlines() shite? This is what perl -n is for!” They’re right; Perl is even better at this sort of thing than Python is. I find that Python hits the sweet spot between the two; others differ.

Notate bene secundus: yes, I suppose I could do similar stuff with a sed/awk pipeline without going into Python. Fuck off.

Notate bene tertius: “orientedly“.

He’s right about all the underscores, though. Constructors being called __init__ is a pain in the arse.

In short, I disagree. However, each to their own and all that…

Update: further discussion on Schwuk’s original post.

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)