Immutable data
Since we're not using variables to track the state of a computation, our focus needs to stay on immutable objects. We can make extensive use of tuples
and namedtuples
to provide more complex data structures that are immutable.
The idea of immutable objects is not foreign to Python. There can be a performance advantage to using immutable tuples
instead of more complex mutable objects. In some cases, the benefits come from rethinking the algorithm to avoid the costs of object mutation.
We will avoid class definitions almost entirely. It can seem like anathema to avoid objects in an Object-Oriented Programming (OOP) language. Functional programming simply doesn't need stateful objects. We'll see this throughout this book. There are reasons for defining callable
objects; it is a tidy way to provide namespaces for closely related functions, and it supports a pleasant level of configurability. Also, it's easy to create a cache with a callable object, leading to important performance...