O'Reilly logo

Seven Concurrency Models in Seven Weeks by Paul Butcher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 should therefore be perfectly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required