Wednesday, May 14, 2008

Things I Hate About You #3: Python

This one's tougher, because my Python isn't anywhere near as good as my Perl or Java.
  1. Whitespace - Low-hanging fruit. The whole whitespace thing is Python's bugaboo the way that speed is/was for Java and a resemblance to line noise is for Perl. But there is still something here, and not the usual "OMG it makes me indent!" that shows up. The problem is that using whitespace as the delimiter causes issues when modifying code later. A very, very common maintenance idiom is taking a block of code and wrapping it with an if statement because you've found cases where it shouldn't be run. In C-styled languages, when using emacs, the usual way I've done this is to put in the if statement, then walk through the code, reindenting each line with the tab key, until it's time to close the block. In Python, if you try this, you will screw up the indentation for each block inside the new block you're creating. More generally, programming in C-styled languages in emacs teaches you that re-indenting with tab does not semantically change the program; that's no longer the case in Python. (Other editors generally have similar concepts; it's not just an emacs thing.) Or, in the general case again - if you lose leading whitespace in a Python program somehow, there is no automatic way to get it back. (This can happen with a bad translation to HTML, a funky mail filter, or many other ways.) Now, there are ways to work around this (ending all blocks with 'pass', '#end if' comments, etc.), decent editor support makes it less of a problem, and there are advantages to Python's approach, but it's not without its issues as well.
  2. PyGTK - Not entirely Python's fault here, I suppose, but PyGTK is quite possibly the least intuitive, most annoying GUI toolkit I've ever worked with. (And, remember, I've worked with both Java AWT and Swing.) GtkTreeView in particular is just plain twisted.
  3. Python People - Mention #1 to a Python advocate, and...hoo boy. Python's got some damn good Kool-Aid, I guess. Any mention that there is possibly a problem with using whitespace as the delimiter is met with either blaming the user ("Well, clearly you shouldn't be editing that way, then") or shifting the issue ("Well, you'd have to fix the indents anyway, right?") and missing the point that making whitespace significant causes issues of its own.
A relatively lame list, I think. Clearly I need a few more years working in Python to build up some good hatred for it.

1 comment:

Unknown said...

I use Python quite a bit these days. I think my three things would be:

1. XML support. Python comes with a collection of XML modules--xml.dom, xml.dom.minidom, xml.sax, xml.etree. They all suck in one way or another. Some have horrible, non-idiomatic interfaces. Some don't implement anything more than the basic XML features. It's a mess.

There are some pretty decent non-standard modules that you can get, but Python desperately needs to have a single, standard, high-quality XML library.

2. Threads. None of the currently popular dynamic languages (Perl, Python, Ruby) have managed to solve the problem of how to do a good job of using multiple CPUs at once. It's a hard problem; I hope someone figures it out someday.

3. Performance. It isn't bad, but Perl is better. It'd be nice if Python was as fast as Perl.