Skip to main content

C'est la Z

Programming Idioms

I just read Jeff Yearout's recent post titled The Beginner's Garden of Concepts. Not directly related but it got me thinking about programming idioms.

I've been using the phrase "programming idiom" for years to describe a short useful recurring code construct. I didn't realize that it was officially "a thing" until doing a web search on the phrase years later.

As our students grow from newbies on I think it's helpful for them to see recurring and related patterns and programming idioms gives us a name to apply to many beginner patterns. An early idiom might be "finding the smallest in a list:"

Another is the very similar and more general "do something on every item in a list:"

By talking about constructs like these as idioms it helps students see and develop coding patterns. It also helps them to build mental abstractions. Each of the above idioms are a few lines of code but each are also a single concept. Students learn to think of them as the concept.

When students learn about list comprehensions in python they'll rewrite the "do something…" more like this:

but the pattern or idea is the same.

Other early idioms might include swapping variables:

and loops until an exit condition are met:

Even more difficult concepts like recursion can be described in an idiomatic way:

Patterns like these, or idioms, come up over and over again. We don't have to explicitly mention them in our teaching but I think it's helpful to our students if we do.

comments powered by Disqus