Neil's News

Polyglot 6: Python

18 September 2004

[Python] Sixth is Python. Good general-purpose language. If there isn't a language which specialises in the desired task (high‑level → Lisp; speed → C; multiuser → Moo) then Python is usually a safe bet. The biggest downside is that when compared with other languages, the documentation is poorly organised and poorly written. The docs are so bad that the only way I could write this application was to dissect the C source code. I'd argue that the 'Python Paradox'[?] is actually caused by everyone but the most determined programmers switching to languages which are properly documented.

Here's the Python source code of the standard colour program. Due to pathetic programming within the Python-GD interface, images are limited to a maximum of 256 colours. Worst implementation yet, and the one that took the longest to program too.

Update from 2019. Obviously the world has changed a lot since this post was written. Python has matured into a friendly and well-documented language. Furthermore, the Python Imaging Library (PIL) can create full-colour images. To the left is a live execution of the PIL version of the colour program (reload for a different pattern). Python source code

On an unrelated issue, let's play with fire:

def maxrec():
function maxrec(){ maxrec(); }
sub maxrec { maxrec(); }

What do they all do? Blow up, obviously. But how they do it is interesting.
Python (like the Moo) runs a bit then spits out a full traceback ending with "maximum recursion depth exceeded". Good. One can debug that.
PHP runs a bit then quits with "Segmentation fault" offering no clue what happened or where. This isn't ideal.
Perl (like Euphoria) runs and runs and runs. There's a giant sucking sound as memory disappears and all other applications on the server grind to a halt. Meanwhile the sysadmin is sweating bullets trying to kill the task before the server falls over.

[Richard, don't even think about it. I know where you live.]

< Previous | Next >

Legal yada yada: My views do not necessarily represent those of my employer or my goldfish.