Day 1: Programming Without Mutable State

When programmers first encounter functional programming, their reaction is often one of disbelief—that it can’t be possible to write nontrivial programs without modifying variables. We’ll see that it is not only possible but very often simpler and easier than creating normal imperative code.

The Perils of Mutable State

Today we’re going to concentrate on parallelism. We’ll construct a simple functional program and then show how, because it’s functional, it’s almost trivially easy to parallelize.

But first let’s look at a couple of examples in Java that show why it’s so helpful to avoid mutable state.

Hidden Mutable State

Here’s a class that doesn’t have any mutable state and ...

Get Seven Concurrency Models in Seven Weeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.