Functional programming is a style of programming that is characterized by short functions, lack of statements, and little reliance on variables. You will learn what functional programming is, and how you can apply functional programming in Python.
In this video course, we will learn what functional programming is, and how it differs from other programming styles, such as procedural and object-oriented programming. We will also learn why and when functional programming is useful, and why and when it makes programs unnecessarily complex. Then we go on to explore lambda expressions, which are short one-line functions, and are the purest form of functional programming that Python offers. Next, we will learn about higher-order functions: functions that accept other functions as argument, or return other functions as return values. In Python, higher-order functions are elegantly supported through decorators. We will also encounter important concepts from functional programming, such as monads, currying, statelessness, side-effects, memoization, and referential transparency; these concepts may initially seem odd to Python programmers, but we will see how they are elegantly supported by the language. In fact, many Python programmers already make use of concepts from functional programming without being aware of doing so.
All the videos in this course contain hands-on examples of the introduced concepts. We will also consider several different implementations of an interactive calculator to illustrate how you can use functional programming in a simple-but-complete program.
About The Author
Sebastiaan Mathôt currently works as assistant professor at the University of Groningen in the Netherlands. He is the lead developer at OpenSesame, which is an open-source, Python-based program for implementing psychology and neuroscience experiments. Sebastiaan is also the designer of DataMatrix, a Python library for numeric computing that is focused on elegance and readability.
Sebastiaan also gives regular workshops on using OpenSesame and Python for scientific purposes, and regularly publishes Python tutorials on his YouTube channel. As such, he has extensive experience in teaching Python and making advanced topics seem as easy as possible.
In this video, we will see how a basic calculator application can be implement using two different programming styles, procedural and functional. By doing so, we will get a first taste of functional programming.
In this video, we will see what statelessness, side-effects, and referential transparency are.
In this video, we will consider two ways of testing code, unit testing and through formal proofs.
In this video, we will consider recursion (functions that call themselves), which is often used in functional programming instead of loops.
In this video, we will consider how functional programming doesn’t always match how humans think of the world as consisting of objects.
Functional programming relies heavily on expressions, and eschews statements. But what is the difference between the two? In this video, we will learn exactly how statements and expressions differ.
In this video, we will look at lambda expressions. This is the purest form of functional programming that Python offers. Lambda expressions are functions that consist of a single expression and which do not need to have a name.
In this video, we will take a closer look at ‘and’ and ‘or’.
In this video, we will consider ‘if’ expressions. These are the functional alternatives to the far more commonly used ‘if’ statements.
In this video, we will consider how you can pass a function as an argument to another function. The receiving function is by definition a higher-order function.
In this video, we will look at nested functions, that is, functions that are defined inside other functions. We will also consider variable scope, that is, from which functions variables are accessible. These are important concepts for higher order functions.
In this video, we will see how a higher-order function can return functions as return values.
Because operators (+, -, /, and so on) are syntax and not objects, you cannot pass them as arguments or return values. To bypass this problem, the Python operator module offers all operators also as functions.
In this video, we will consider decorators. Decorators are an elegant and Pythonic syntax to implement specific kinds of higher-level functions.
In this video, we will consider decorators that accept arguments. This makes the decorator design pattern even more flexible.
In this video, we will look at currying, a technique for turning a function that takes multiple arguments into a chain of function that each take one argument.
In this video, we will look at monads. Most discussions of monads are complicated, and use lots of mathematical terminology. But, as we will see in this video, the idea of monads is really simple.
In this video, we will look at memoization, which is a technique to optimize code by storing return values of functions.
In this video, we will look at exceptions, which are the standard Python approach to error handling.
In this video, we will look at an alternative approach to error handling, using a Maybe-like decorator. This resembles the Maybe monad, but takes a more Pythonic approach.
In this video, we will take everything that we’ve learned, and use this newly acquired knowledge to polish the interactive calculator that we developed at the start of this section with the help of all using a functional programming style.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.