VIDEO: https://www.youtube.com/watch?v=2CWEg64qZnY (Sydney)
Did you ever wonder: Is functional programming hard? Do you have to be a math whiz? What about the jargon? This talk has answers.
Functional programming is sometimes perceived to be unapproachable, with unfamiliar jargon, obscure concepts, and bewildering theories. This seems counter to its main aim, namely to simplify programming and to make programming more widely accessible. In this talk, I like to argue that there is nothing inherently unapproachable or complex in functional programming, at least not beyond the complexity inherent in programming in general. Instead, we need to critically analyse our teaching strategies and ensure that they are appropriate for a broad range of developers. In my experience, the most common pitfalls are (1) to start with abstract concepts instead of with concrete examples and (2) confusing the historic development of a concept with a pedagogically appropriate teaching strategy. A good example of the latter problem is any attempt to explain the use of functors and monads in functional programming by appeal to category theory. Explaining an unfamiliar idea with an even more alien idea is generally a futile endeavour.
We avoid the first problem by leading with concrete examples, which we use to infer recurring patterns of computation and to motivate more abstract language features — for example, by demonstrating how higher-order functions facilitate the removal of duplicate code. We avoid the second problem by focusing on the concrete computational reasons for using a particular concept or language feature; that is, we place the why before the how. For instance, in sample code that requires maintaining shared state, a state transformer monad helps us to remove error-prone plumbing code.
Nevertheless, we have to acknowledge that moving from imperative, object-oriented programming to functional programming requires more effort than learning yet another object-oriented language. The key here is to clearly distinguish new concepts from known ideas that are just presented differently. Some concepts simply have different names (such as structs versus product types), some have different syntax (such as functional application without parenthesis in Haskell), and some are expressed differently (such as while loops versus tail recursive functions). In all cases, we can help learners by establishing a correspondence between the known and the superficially new.
Putting all of this together, teaching and learning functional programming is surprisingly straight forward. Still, we can do even better. Given the importance of working from examples and for students to experiment by quickly exploring a design space, ideas from live programming tighten the feedback loop and provide a distinct improvement for teaching over the classic REPL (read-eval-print loop) introduced with Lisp. I will demonstrate these improvements using Haskell playgrounds in the Haskell for Mac IDE, but the same applies to Swift playgrounds in Apple’s Xcode IDE and the Swift Playgrounds iPad app.
The material presented in this talk is informed by the experience that Gabriele Keller and I accumulated over a decade of teaching Haskell in a variety of courses at UNSW (University of New South Wales) to thousands of students spanning from absolute beginners to experienced developers in postgraduate courses. We experimented with a variety of approaches and performed student surveys to refine our approach over time. We wrote a textbook providing an introduction to computing for first years students and more recently an online Haskell tutorial including screencasts that feature live coding.
This talk was presented at four YOW! Nights in March 2018 in Sydney, Melbourne, Perth & Brisbane: http://nights.yowconference.com.au/archive-2018/yow-night-2018-sydney-manuel-chakravarty-mar-6/