Talks: Writing Functional Code in Python

Presented by:


Description

Intro (2 min)

In this talk, we'll define exactly what functional programming is and how it helps us. We'll explore the main concepts from functional programming and see how we can apply them to our Python code going over some concrete examples.

What is Referential Transparency (3 min)

We'll look at how we can prove if a function is pure or not, and what the implications are of writing our code more explicitly. We'll look at an existing snippet of code that uses mutation and how we can transform such a function into one that is referentially transparent.

Handling Emptiness: The Option Monad (7 min)

We'll go over a concrete example of using branching logic and nested ifs to check for emptiness. Again, we'll transform this code by using the Option monad and make our code more readable and robust.

Handling Exceptions: The Try Monad (7 min)

We'll take a look at dealing with exceptions using the try..except syntax. We'll change this to using the Try monad and see how our code reads from left-to-right and how we can make the side-effects of our functions more explicit to the caller.

Handling Asynchronous Calls: The Future Monad (8 min)

We'll take an example which uses threads and processes and change it into an example that uses the Future monad. Along the way, we'll see how we can more explicitly handle asynchronous behaviors and their effects.

Conclusions and Takeaways (3 min)

We'll conclude by looking at the pros and cons of functional programming and where we can use it in our Python code.