I Know Py Foo

Last updated: Tue, 24 Mar 2009 23:03:00 GMT

I know Python in almost exactly the same way as Keanu Reeves knows Kung Fu: observed from a distance, through a select series of fixed viewpoints, with a trillion dollars of post-production, I might look like a fricken ninja.

Up close and personal, though? Eh, we'll see.

In a practice I'm sure I share with many programmers, when I want to learn a new language I try to solve a small and well-defined problem with it. I have a couple of favourite problems to solve. After "Hello, World!", the Non-Intelligent Language Learner has been my favourite toy app. I've re-implemented the same system in Ada, C, C++, Perl and PL/SQL, using data structures and tools appropriate to each language.

Yes, that means recursive tables under PL/SQL and multi-dimensional digraph pointer hell in C.

Fun!

This weekend, I got a hankering to learn Python.

The first language learner example I came across was an Amiga demo called NIALL, back in early '90s. The 'A' in NIALL stands for AMOS. My friend Greg tossed me a floppy torn from the front of some magazine or other and, six hours later, the sun came up again and I was still hunched in front of his A1500 trying to maintain a conversation with a couple of hundred lines of BASIC.

I've no idea whether NIALL was the first, or just the first I saw. I've seen or heard of a few other re-implementations since then. I am not associated with any of them. They might be fantastic, I just don't know.

The Perl incarnation of NIALL I wrote was also my introduction to CGI programming, and made its way onto the intarnets some time late '96, under the name Nicole -- Non-Intelligent CGI Language Learner. It got some real and actual traffic, and the conversations I recorded made for some interesting reading. Ironically, while I chose the name Nicole to avoid the obvious NIPLL ('P' for Perl) the female name made for some exceptionally perverted conversation logs.

Unlike Eliza and chums, NIALL has never been about passing the Turing Test. But, if it had been, and if the panel was comprised solely of drunken Scandanavians, I'd be a darn sight richer than I am now.

Anyhoo, I've "learned Python", and a few other things along the way:

  • The Learning Python book isn't bad at all. Not O'Reilly's finest, but a pretty good read for all that. The usual handful of typos, but nothing major. The "Why You Will Care" sections and regular summaries and gotcha lists seemed to hit close to the sweet spot, for a guy who used to be a real programmer a long time ago, but hasn't used any of these fancy concepts in anger in a decade.

  • The indentation-as-block-delimiter markup scheme is exactly as annoying as I thought it'd be. Orthography is a good idea, this is misuse close to abuse. That might just be old dogs and new tricks. Or should that be old tricks? Let's punch-card party like it's 1899, dudes.

  • If you think you know class attributes and instance attributes from C++, think again. They're ever so slightly simpler under Python, and ever so slightly confusing if you're still thinking C++.

  • Yes, implicit declaration will bite you in the ass.

  • Dynamic typing and polymorphism are cool and all, but there's obviously something I still have to get my head around, because I just can't stop wanting to know the types of the arguments I'm passed. I have this burning need to overload constructors, for instance.

All that said, get yer trumpets at the ready because here it is, my Non-Intelligent Python Language Learner: NIPyLL

And if you want, you can play with NIPyLL online.

I don't know what this says about whom or what -- it's at least five years since I learned a new language -- but this incarnation of NIALL is the simplest yet. The earlier revisions, before I went all OO and pared things out into separate classes, were beautifully clear and concise.

It might be me. But Python might have legs after all.