3 ms·
> The actual point of FP, as I see it, is that it decouples a function from the context it is executed into. I 100% agree with this. To me, a rough measure of
by yen223 9y ago
> The actual point of FP, as I see it, is that it decouples a function from the context it is executed into.
I 100% agree with this. To me, a rough measure of code simplicity is the amount of additional context you need to be able to reason about any specific function or object. Pure, statically-typed functions are close to ideal - all the context you need is encapsulated within the function definition itself.
Functions in dynamically-typed languages are trickier - in addition to the function definition, you also need to know how the function was called, since there's no guarantees about the arguments that were passed in. Impure functions are the worse - if the function interacts with global state, then you'll need to be aware of every callsite that interacts with global state. Practically speaking, that means you can't reason about anything in isolation - you always need to hold the entire program in your head. Hence the whole "globals are evil" mantra.
Thinking in terms of functional purity gives a convenient way to write clean code. I definitely recommend every programmer at least be familiar with the concept.