Functional programming and concurrency
We have already hinted at it throughout this book, but the ideas behind functional programming can help us write concurrent code. Typically, thinking about concurrency is a bit of a headache, even when a language has modern tools to support it, such as goroutines and channels. Before we dive too deep into this material, let’s first take a small detour as a refresher on what exactly we mean when we talk about concurrent code, and how it compares to parallelism and distributed computing.
Concurrency, parallelism, and distributed computing
The terms concurrency, parallelism, and distributed computing are, at times, used interchangeably. And while they are related, they are not exactly the same thing. Let’s just point out what we mean by concurrency first. Concurrency is what happens when our program can execute multiple tasks at the same time. For example, when we are playing a video game, typically a thread is playing audio,...