June 29, 2010: The Violas of Programming

Orchestral musicians make jokes about violas and viola players. "What's a string quartet? A great violin player, a mediocre violin player, a bad violin player, and a cellist." Or, "What's the difference between a viola and a trampoline? You take off your shoes to jump on a trampoline." But violas are as essential as they are unglamorous: hardly anyone plays them as a lead or solo instrument, but string quartets just don't sound right without that third voice.

I realized today that Python's sets [1] are sort of like the violas of programming. They come up quite naturally all over the place—just flip through any text on algorithms and count how often they're used. But they're rarely used alone, which makes it hard to come up with well-motivated examples when teaching them. Consider:

I didn't worry about this too much in the Version 3 lecture on sets and dictionaries: I used a couple of completely abstract examples (including "which vowels"), and moved quickly into a discussion of how sets are stored and why their values have to be immutable. I'd like to do better in Version 4—I'd like every new tool or technique to be well motivated at the time of its introduction—but I'm damned if I can figure out how.

[1] Disclaimer: As the author of the original Python Enhancement Proposal (PEP) on sets, I have certain biases.

< OlderNewer >

This post originally appeared in the Software Carpentry blog.