3 ms·
> Well, you might say mutating a variable is not functional programming - but i don't care, my function is still pure and it is referentially transparent and i
by alextheparrot 9y ago
> Well, you might say mutating a variable is not functional programming - but i don't care, my function is still pure and it is referentially transparent and i don't have to think a lot about the various choices that i may have to do the same thing (map, reduce, etc etc).
I completely agree with this. I think the core advantage of functional programming is the ability to generalize across contexts, which is what makes the purity of the function an important feature. The standard library for Scala is full of while loops and mutable buffers, because if the function call is pure you can then optimize performance through these.
If I make a new context “HasLength” with a single function, “length” and implement it for List, it doesn’t matter how that “length” function is implemented, just that the only context it is bound to is the List one. On the other hand, when implementing “length” for a distributed context, the map-reduce way is probably much easier and more efficient to implement rather than trying to coordinate sistributed variables manually.