A Fugue about Paradigms and Functional Programming

  • Presenters: Emmanuel Gaillot & Christophe Thibaut
  • Type: Kata session, as done in the Paris Coders' Dojo. This is an interactive programming session.
  • Duration: 90
  • Audience: Participants should know about programming, OO and TDD. Prior knowledge about functional programming is welcome, although not necessary.
Objectives

This workshop's objectives include:

  • exploring Test Driven Design practices in a Functional Programming flavor -- or vice-versa
  • discovering some new ways to code a domain problem with no domain object
  • thinking in terms of calculus and values instead of behaviour, state and collaboration
  • thinking about accidental and essential complexity
Abstract

Test Driven Design is quite frequently introduced within an Object Oriented Context. Many tutorials and books about TDD are written for Java, C#, or Ruby. One might think TDD is intended only for OO programming. On the other hand, Functional Programming (FP) languages have flourished on a tradition of formal reasoning about programs, in which proving code is sometimes preferred over testing it... TDD and FP: do those two mix well?

TDD rules are quite simple: write a failing test, make it pass, refactor code. Behind the rules -- TDD principles include doing the simplest thing that could possibly work, write expressive code and eliminate redundancy. Could we obey such principles while programming in a language that isn't OO?

Sure we can! In the workshop we will program a small problem the TDD way, using immutable values instead of mutable object states, functions and expressions instead of object behaviour and lexical closures instead of object collaboration.

Such a programming adventure will happen in the form of a (Paris Coders' Dojo) kata session in Haskell, a session during which the developer and driver write the full code directly in front of -- and with the full collaboration of -- the audience, submitting their design to everybody's questions, comments, suggestions and approbation.

We will explore some of the most useful functional programming topics, including :

  • data structure made simple and expressive: lists, generators
  • generalization trough lexical closures
  • avoiding intricate control structures with pattern matching and recursion
  • reliability granted by referential transparency
  • clear boundaries between "pure" functions and intended side effects
Our intent is to assess the applicability of FP languages and tools to writing code that meets TDD standard criteria : passes all the tests, expresses intention, no redundancy, economic in terms of lines of code. In particular we'll try to see how well specific functional programming idioms may help us writing smaller, more expressive tests, and give birth to elegant ways to make them pass.

Debriefing the dojo session will also give us an opportunity to think more about the notions of accidental and essential complexity, and the representations underlying the way we model a solution for a given domain problem. Furthermore, as many OOPL now feature some functional constructions, we will also discuss about blending OOP and FP flavors, and get the best of both worlds.

Benefits of participating

Participants will

  • learn about Haskell and its suitability to complex systems,
  • learn about coding in a functionnal programming language the TDD way,
  • learn about how they can add an FP touch to their current programming style,
  • discuss and compare OO and FP design specificities,
  • have fun, make friends and connect with people from the FP community.

What will the organisers learn

The organizers expect to

  • learn more about functional programming and its applicability to some domains they didn't think of,
  • learn more about how to efficiently communicate their interest and knowledge about FP paradigm,
  • have fun, make friends and connect with people from the FP community.
Session Outline

  • 5 mn: introducing ourselves to each others
  • 10 mn: introducing the basic principles behind FP
  • 60 mn: unfolding the kata in Haskell
  • 15 mn: debriefing and debating about what we learned