Thursday, December 09, 2004

The Perception of Speed

Glyph Lefkowitz (of Twisted fame) hits the nail precisely on the head, with this incisive summary of why C programmers think Python is slow. After Guido asked the python-dev list for ideas on combatting this common perception, I suggested that adding a compiler -- however primitive -- would help. Glyph, however, went one better; he effectively pointed out that all we really need to do is stop saying, "rewrite speed-sensitive code in C". Instead, we should be saying "add type declarations to speed-sensitive code, and compile it with Pyrex." As a practical matter, Pyrex is C with Python-like syntax, anyway, at least if you type-declare everything to death.

As for me, I totally don't get the idea that Python is slow. It still boggles my mind every time I run 'timeit' on some operation and it comes back as taking half a microsecond on my desktop PC. My first computer couldn't do anything in half a microsecond, even if it was a single assembly instruction! And then I programmed in interpreted Basic for the better part of a decade, using assembly for speed-sensitive parts.

"Sheesh. Why these kids today, they don't know what it's like. Back in my day, we had to program five miles uphill every morning through the snow to get to school... and don't get me started about unit tests. Our unit tests were, we read the entire program and pretended to be the computer because we couldn't afford a computer to type the program into. And we liked it!"

[Feel free to continue this rant in the comments, by contributing stereotypical rambling-old-man jokes about how things were so bad in the old days and today's programmers are spoiled brats by comparison.]