Higher Order Javascript

Location: Portland 255
Average rating: ***..
(3.29, 24 ratings)

A whistle stop tour of what the ability to write functions that manipulate and construct other functions means. Learn how to use functional programming techniques to:

  • Factor your code better by extracting the ‘shape’ of computation
  • Use techniques like memoization to improve efficiency without resorting to less immediately comprehensible algorithms
  • Use Streams to implement the ‘endless page’ pattern cleanly

Understanding higher order functions was one of the key moments in my programming life. Once you understand them, a whole new way of thinking opens up to you. Come and get your head stretched and your horizons broadened.

Photo of Piers Cawley

Piers Cawley


Piers Cawley started programming Perl in the mid nineties, but recently spent a few years working as a Ruby programmer.

He’s currently working for the BBC, applying Modern Perl techniques to MediaSelector, part of the iPlayer backend.

He used to write a weekly summary of developments in Perl 6 for the perl.com website.

Comments on this page are now closed.


Curtis Fulton
08/01/2011 4:05am PDT

The JavaScript -> CoffeeScript bait-and-switch was a total bummer

Picture of Ricardo Signes
Ricardo Signes
08/01/2011 12:16am PDT

When the talk started, I said to a friend on IRC that I thought using CoffeeScript was probably a good idea. By the time the talk was done, I still wasn’t sure. It’s much more compact to read than JavaScript and even though I never use CoffeeScript, it has always seemed quite easy to sight-read. I think using it was a good idea.

There were two things about it that I found problematic, though. The examples were often mathematical, which almost never engages me. When I’m told that something is awesome because of how I can use it to list primes, I turn off. It doesn’t appeal to the “solve real problems” urge in me, even though I know that if I think about it long enough, I’ll see how it relates. (I don’t come to conferences to think by gosh!)

There were also a number of places where the CoffeeScript’s compactness led to code that was difficult to scan. I’m sure I wrote it down but now can’t find it. Things like: lenapply (x) -> (f, x) -> (1)

We might write our code like that once we understand FP, but it makes the audience work a lot harder than long-named variables.

Still, learning these techniques is really transformative to how programmers think about problems, and I think this was a good talk that can be further improved to be even better.

Scott Sadler
07/29/2011 3:13am PDT

Piers, I’m wondering if you use Python at all? Some of the things you presented are supported by standard libraries (functools, itertools). I think the first part of your presentation was basically about “partial function application”, which is fairly common. Anyway, an enjoyable talk nonetheless!

Scott Baker
07/29/2011 2:46am PDT

I only understood about 20% of this talk, but it was super interesting.

Picture of Piers Cawley
Piers Cawley
07/29/2011 12:48am PDT

If I’d done the slides in JavaScript, the ideas wouldn’t fit on the slides. Believe me, I tried.

If it helps, there’s a write up here the examples are still on coffeescript, but neither are they flying by. Also, someone in the comments provides a link to a translation into JavaScript.

There’a a second article on asynchronous streams which covers the “endless page” pattern that I didn’t get to in the talk, especially useful if you’re looking for something a little closer to the real world.

Deborah Lewis
07/28/2011 1:59pm PDT

Using coffeescript was a distraction; the ideas would have been better communicated using std javascript that most are familiar with so that the focus could be on the concepts rather than the expression.

Picture of Fred Willerup
Fred Willerup
07/28/2011 9:38am PDT

i am a fairly experienced javascript developer but didn’t really understand how to apply this. Perhaps the coffeescript distracted or the fact that i came in late!

Garth Williams
07/28/2011 9:15am PDT

Not sure why javascript was in the title… misleading.

Steve Rippl
07/28/2011 8:56am PDT

The coffeescript might have been an abstraction too far when presenting ideas so new to me. I realize the examples would have been far larger and perhaps lose some of their elegance, but some more familiar terrain might have helped me to grasp the larger concept more readily?

Great concepts to try and absorb through!

Picture of Augustina Ragwitz
Augustina Ragwitz
07/28/2011 8:18am PDT

Excellent examples!! It was great to see a Perl programmer’s perspective on JavaScript (my second favorite language with Perl coming first). I’ve been working my way through Higher Order Perl to better understand functional programming and found Crawley’s examples and presentation to be highly relevant. I docked one star just because there were some technical difficulties and he seemed to go through the material fairly quickly so I couldn’t absorb it as much as I would have liked.

Picture of Dirk Bergstrom
Dirk Bergstrom
07/28/2011 7:52am PDT

Using Coffeescript was a distraction—I had to mentally decode unfamiliar syntax before I could think about the unfamiliar concepts. In the more interesting slides I couldn’t do both fast enough to get real value. I understand the reasoning behind the choice, but I think it was a bad tradeoff.

Other than that, great talk.

Ben Brewer
07/28/2011 7:34am PDT

Enjoyed the presentation but was expecting examples to be in javascript, based on the title. With no exposure to coffeescript, I found it a distraction from the core concepts.

Picture of David Copeland
David Copeland
07/28/2011 7:25am PDT

I missed the first few minutes, but I have to say, using Coffeescript made things more obtuse, and mathematical examples just don’t resonate with me at all. Would prefer some more domain focused things that a JS developer might encounter outside of a job interview

Picture of Jeremy Mikola
Jeremy Mikola
07/28/2011 7:25am PDT

Using Coffeescript helped keep the code and slides concise (great for presenting functional programming). Also a good mix of scenarios covered (memoization, streams, primes calculation).

Looking forward to posted slides so we can play with some of the example code.

Mark Deason
07/28/2011 7:23am PDT

It’s gonna take me a bit to digest this, but I am intrigued.