Understanding Functional Programming

Learn about functional programming.

We'll cover the following

Functional programming

The paradigm of functional programming has been around for a long time but has gained in popularity in the last few years. It is now considered one of the more interesting paradigms by many programmers.

We can trace its roots back to Lambda calculus, which was introduced in the 1930s. In the 1950s, the programming language Lisp was developed and implemented this paradigm.

As we’ll see, this paradigm has a very different approach to how programs are structured and implemented. You’ll need to rethink the way you look at programming and code structure to be able to understand the strength of this paradigm.

We’ll begin by looking at the definition of functional programming. The definition itself will be hard to understand, so we’ll also need to look at some parts of it to understand what this is all about.

One definition is as follows:

“Functional programming is a way of structuring a computer program that treats computation as the evaluation of mathematical functions and avoids changing the state of the program and the use of mutable data.”

Let’s start by deciphering this definition. The “treats computation as the evaluation of mathematical functions” part might sound a bit daunting. If we look closely at this, we’ll see that this is rather straightforward. Let’s take a look at two mathematical functions and see how we can use and understand them in order to understand what the definition of functional programming is talking about.

Pure functions

We’ll start simple with the following function: y=xy=x.

Here, xx is the input we provide to the function and yy is the result. This simple function just states that whatever value we pass to it, it will also be returned. A diagram for this function is shown below:

Get hands-on with 1200+ tech skills courses.