3 ms·
"FP works great for distributed systems, and most software written today is distributed." According to Grokking Simplicity[1], good functional programming isn'
by Leftium 3y ago
"FP works great for distributed systems, and most software written today is distributed."
According to Grokking Simplicity[1], good functional programming isn't about avoiding impure functions; instead extra care is given to them. These functions depend on the time they are called, so they are the most difficult to get right.
Compare to pure functions: given the same input, the results are always the same regardless of when the function was called. So they are easier to reason with.
There is actually a level that is even easier to reason about than pure functions: plain data.
So functional programmers prefer data over pure functions over impure functions.
The reason to avoid "leaks" is because impure functions cause everything that calls them to also become impure. However, it is OK to use local mutation contained to the function itself. Sometimes mutation is simpler and doesn't affect the purity of the function that contains it.
Another good book on practical functional programming is Domain Modeling Made Functional[2]. Actually all of Scott Wlaschin's material[3] is very good!
[1]: https://www.manning.com/books/grokking-simplicity https://www.manning.com/books/grokking-simplicity
[2]: https://pragprog.com/titles/swdddf/domain-modeling-made-functional/ https://pragprog.com/titles/swdddf/domain-modeling-made-func...
[3]: https://fsharpforfunandprofit.com/ https://fsharpforfunandprofit.com/