Summary
In this chapter, we looked at pure functional programming. First, we looked at what exactly it means for a programming language to be pure and functional as opposed to impure and functional. Next, we took a more detailed look at how pure code can help improve testability by eliminating side effects. We also learned that pure code gives readers more confidence in the code that they are reading since functions are more predictable and won’t change the state of the system. We also discussed when we should not use pure functions, such as when dealing with functions that should generate random behavior for games or functions that deal with I/O.
Although we have only briefly touched on it, we have seen how immutability plays a core part in writing pure functions by not changing the values of structs. In the next chapter, we will take a deep dive into immutability, how it does (or doesn’t) impact performance, and how we can leverage this in combination with pure functions...