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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access