Friday, May 15, 2015

FP from the Fire Hose

Earlier this year I gave a presentation at work entitled "Functional Programming (FP) from the Fire Hose." My goal was to present, to a mostly OOP audience, some of the basics of FP while also providing examples that show that FP isn't just academic. You can't sell people on FP with concepts alone. People's eyes just glaze over and roll back into their heads when you start talking functional concepts like first class and higher order functions, immutability, statelessness, referential transparency, homoiconicity, and the like (I won't even say the M-word). With that in mind, I tried to go fast on FP and show several clear examples that demonstrate FP in action, even at a very small scale.

In my presentation, I do (or attempt to do) the following:
  1. Explain FP in 5 minutes to an OOP audience
  2. Explain why functions are important using collections as the context.
  3. Explain that first class functions are a necessary but not sufficient condition for FP. You also must have immutability.
  4. Solve a small problem in both FP and OOP style. The examples, written in Clojure and Java, respectively, show the simplicity and power of FP vs. traditional OOP.
  5. Demonstrate how you can write functional code in a stateful application using Clojure concurrency primitives.
Here's the video and links to additional resources. I hope you enjoy.



The slides are here, and the accompanying repo and demo are here.

If you liked this page or learned anything from it, please tweet the link,follow me on Twitter, and/or follow this blog. Your support and interest is the fuel that drives the effort.

2 comments:

  1. I've enjoyed the slides (sorry, I haven't yet have time to watch the video) and I have one little suggestion about conway's life: use an atom instead of a ref. refs are used when there is more than one and you need a transaction semantincs for all the modifications. If there is only one thing whcich varies, you aonly need an atomic modificatios, so you use an atom.

    Juan Manuel

    ReplyDelete
    Replies
    1. Thanks for the feedback. You are right that an atom would have been the better concurrency primitive for this example. I did use an atom for my ClojureScript version here: http://fn-code.blogspot.com/2015/03/conways-game-of-life-demonstration-and.html.

      Delete