2 Functional programming techniques for concurrency
This chapter covers
- Solving complex problems by composing simple solutions
- Simplifying functional programming with closures
- Improving program performance with functional techniques
- Using lazy evaluation
Writing code in functional programming can make you feel like the driver of fast car, speeding along without the need to know how the underlying mechanics work. In chapter 1, you learned that taking an FP approach to writing concurrent applications better answers the challenges in writing those applications than, for example, an object-oriented approach does. Key concepts, such as immutable variables and purity, in any FP language mean that while writing concurrent applications remains far from easy, developers can be confident that they won’t face several of the traditional pitfalls of parallel programming. The design of FP means issues such as race conditions and deadlocks can’t happen.
In this chapter we’ll look in more detail at the main FP principles that help in our quest to write high-quality concurrent applications. You’ll learn what the principles are, how they work in both C# (as far as possible) and in F#, and how they fit into the patterns for parallel programming.