exploring the lattice

Grokking Python

Kirby Urner

--

Probably most of us know that the verb “to grok” was coined by Robert Heinlein in his novel Stranger in a Strange Land, about a dude raised by Martians having to adjust to life on Earth. “Grok” was a Martian word and meant “to comprehend deeply” or something like that.

Python is a computer language (general purpose) named after Monty Python (which was named after what again?), the British comedy troupe famous for its quirky skits on BBC television. Guido, a Dutch prodigy in Amsterdam at the time, could tune in the BBC and Monty Python gave him a useful set of memes to work with.

Naturally, the “nasty snake” associations have built up also. Pythonistas actually get a lot of mileage from snake metaphors, or at least I do.

When I introduce Python, I might start with a picture of a snake’s skeleton (too scary?), to emphasize the proposition that “snakes have lots of ribs”. Then I’ll spell the word “ __ribs__” in this funny way, with those two underline characters in front and behind the letters.

Or if I want the singular, I’ll write “__rib__”.

Why? What’s that all about?

snakes (including pythons) have lots of ribs

As Pythonistas well know, at a deeper level than simply using Python like a calculator — and it shines in this role — we have the power to take advantage of Python’s type system, meaning we’re free to invent new types of our own.

“What’s a type?” you might now ask, while fighting the urge to glaze over and move on to other topics. It sounds very technical.

Just stick with the ordinary English meaning and you’ll soon “grok” how Python works.

We know that Dog is a generic type of animal, but then we have many specific breeds of dog, and within the many breeds (including the mutt, or mongrel breed) we get specific dogs, the actual “instances of the Dog type” named Fido and Rover and so on.

So in Python, when defining a Dog type, you think about the things dogs do, such as bark and wag their tails. You also think about what dogs contain (yes, anatomically for starters) and/or what properties we might associate with a given dog, such as color…

--

--