Functional real world

Posted on Thu 02 June 2016 in english

Today I listened to episode 41 of the Functional Geekery podcast with guest Eric Normand. Eric talked about teaching functional programming ideas, wherein he already has broad experience from doing LispCast, Closure Gazette and

His idea of how to teach functional basics is simply brilliant. Instead of providing mathematical examples or rather formal definitions like the following:

Reduce definition taken from Michael Fogus' 'Functional JavaScript' book

reduce collects a composite value from the incremental results of a function supplied with an accumulation value and each value in a collection

Eric came up with the following easy-to-understand example:

"My daughter made some macaroni art. You have 3 parts of a reduce:

  • You have the action - the function you're calling on it (which is glue())
  • you have the initial starting value (which in this case was piece of card stock) and then
  • a collection (in this case is a collection of macaroni).

She went through one piece of macaroni at a time calling that action glue() on the initial value. In the end she had piece of macaroni art.

It things like that I'm searching for. Something visual because people can imagine it. Any other explanation of reduce is boring and it's not gonna stimulate that real understanding so you can start using it." - Eric Normand

I second Eric's view on that topic. We need more non-abstract real world examples to teach computer science-y stuff in general. Formal definitions and mathematical equations are not gonna stick in your mind as easy as some weird macaroni example. It's too damn funny to forget.

Call to action: Create some good real world examples!

Update: Jeremy W. Sherman provided another example for reduce: "let's squish this accordion down by swizzling out cons for another binary function".

Update 2: Map/filter/reduce in a tweet.