x things I hate about python

Sun, 03 Jun 2007

So I just realised that both the applications I've demonstrated here have been in python. This makes me laugh, because these I think are the first two python applications I've built (I've modified plenty of python before, but never started a python project). So I'll be clear and say that this isn't a place where I use python for everything. So then, on to the python bashing:

  1. Built in functions - I don't care if they are named sanely, there are too many of these (len(dir(__builtins__)) == 134), and I won't remember them. These functions don't look anything like the basis set of vectors I would use for describing every program. Obviously the language designers didn't view things the same way as me, and that is cool, but I much prefer a small language.
  2. Recommending spaces for indentation - another popular holy war. But using spaces for indentation is wrong. If I'm viewing code, I want to choose how much indentation there is (in fact, on my widescreen laptop, I use 4 spaces but on this desktop I use 3 spaces - and at work I think I use 2). I disagree about mixing tabs and spaces also. Spaces should be used for alignment, and tabs for indentation. They have different purposes, so they shouldn't be mutually exclusive (for example, alignment of a multi-line condition should be done with spaces). Finally, if I'm wrong, then it is much easier to convert from tabs to spaces than from spaces to tabs (and one of my internal heuristics says that this means that tabs are right).
  3. Ugliness. After reading the start of any python tutorial, you will think that python is a nice looking language. Then you get the the section on classes, and are greeted by functions like __init__, or is that _init_ or ___init___ - fortunately everyone writes code in a monospace font. But I'm still struggling to come up with a reason why we needed these extra __ at the end. Why not just __init? (or just say what you mean: def private init(self):. Which then exposes another ugliness which I'm sure people have complained about before - the "self" parameter. Unless I'm missing something, it could be made a keyword, and then we wouldn't have to include this parameter in every method.
  4. Anonymous functions suck. Simple functions are fine inc = lambda x: x+1, not so simple functions aren't: factorial = lambda n: reduce(lambda x,y: x*y, xrange(1, n+1), 1), isprime = lambda n: itIsEasierToJustWriteANamedFunctionAndCallItHere(n). Maybe this whole restriction of having a one-liner for an anonymous function was a design decision, because any function more than 1 line long should have a name. I think that this should be the programmer's judgement call, not the language's.
  5. (Just because the documentation is in front of me): The function raw_input gives you the raw input... minus the newline.
  6. Most of my python experience was in a situation where a debug cycle took about 30 seconds. I don't care that you can make a .pyc file that has abs("string") represented in it, that doesn't help me.
  7. The fate of reduce(). Well, I suppose my previous point about anonymous functions is being taken care of... by getting rid of them. How about getting rid of anonymous integer literals too? Sure, it would prevent you from finding code with magic number sprinkled all over the place with no indication about where they came from, but I'd love to see your "using python as a calculator" tutorial after the change. Why do people hate functions?

There are other things that irk me about it, generally the typing situation annoys me the most, then the whitespace, then the anger towards functional programming. I don't think it is going away, and I'll probably keep on using it because it has lots of good libraries for it. But I'll never be happy about it, and it looks like things are only going to get worse, since these seem to be things where I have different opinions to the language designer, not just because these things were oversights.

You're forgetting one of the biggest nuisances of Python -- module loading. Apparently Guido van Rossum thought it would be a terrific idea to have module name resolution include the file you're already executing, so if, for example, you want to write a SQLAlchemy test script, and name it ~/test/sqlalchemy.py, and try to 'from sqlalchemy import *', you're going have fun spending an hour figuring out why none of your imports are resolving because _your goddamn script is trying to import itself_.
Jeff Goldschrafe
91 days after story
Name & email are optional. Email will not be obfuscated.
HTML tags will be removed except hyperlinks.
 

About

I'm a nerd living in Sydney. This is a place where I can write stuff about my interests and not care that no one else is reading.

I like music, maths, programming, pretty pictures, filters and other good things.

(more info)

It should be fairly obvious that this isn't connected to my employer at all.

Email me (not a catchpa)

Email policy

Subscribe

RSS Feed RSS

Get an aggregator

Liferea (Linux)

Vienna (OSX)

Feedreader (Windows)

Google Reader (Web based)

I've only used Liferea, so I can't vouch for the other ones.

About this site

This site runs a (modified) version of blosxom.

The host is GeekISP, and they seem to do an excellent job.