Functional programming and data mutability

Pure functional programming is one of the best practices in functional programming and you should stick to it. Writing pure functions will make your programming life easier and you will be able to write code that's easy to maintain and extend. Also, if you want to parallelize your code then it will be easier to do so if you write pure functions.

If you're an FP purist, one drawback of using functional programming in Scala is that Scala supports both OOP and FP (see Figure 1), and therefore it's possible to mix the two coding styles in the same code base. In this chapter, we have seen several examples showing that writing pure functions is easy. However, combining them into a complete application is difficult. You might agree that advanced topics such as monads make FP intimidating.

I talked to many people and they think that the recursion doesn't feel reasonably natural. When you use immutable objects, you can never mutate them with something else. There aren't times when you are allowed to do that. That's the whole point of immutable objects! Sometimes what I have experienced is that a pure function and data input or output really mixes up. However, when you need to mutate, you can create a copy of the object containing your mutated field. Thus, theoretically, there's no need to mix up. Lastly, using only immutable values and recursion can potentially lead to performance problems in terms of CPU usage and RAM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.228.180