Monday, March 26, 2012

A great example of the power of generators

Sophisticated programming language concepts are often hard to explain, and so it's great when you find something simple, clear, and immediately persuasive.

For example, generators are one of those things that are hard to grasp.

So I really enjoyed Ned Batchelder's elegant and simple example. It has just enough complexity to make the solution real-world, it is motivated by a common and realistic problem, and it demonstrates an elegant use of the feature.

As many of the commenters point out, there are other possible solutions, but that's not the point! The point is to illustrate the use of generators without descending into programming language theory or resorting to pages and pages of code.

Anyway, nice article, Ned!

No comments:

Post a Comment