Notes on The Promises of Functional Programming

More robust. More compact. More easily parallelizable.

These are the promises of functional programming, and this functional dream consists of:

 

1. Immutability

Avoiding mutating (that is, changing) data! Instead of manipulating datum as it is, return a mutated copy of that datum. Differing from datum access in imperative languages, functional programming filters the datum’s value through a set of functions. By avoiding these ambivalent states, we get to circumvent debugging nightmare from hard-to-trace changes, which ultimately facilitate concurrency and parallelization by both removing the need to coordinate datum transformations to prevent deadlocks, and securing a coherence in results given an inputted set of values: Referential Transparency.

 

2. Referential Transparency

Basically, a function works just like any other mathematical function. Every value in a function’s argument domain maps to just one value belonging to a function’s range. So, when I am adding 2 + 2, I always want to get 4, not any other value. That is really it. No mystery boxes. No invisible hand. No faith. Just pure coherency, and, thus, the power of order in prediction: cosmos, instead of chaos; a debugging delight.

 

3. First-Class Functions

Functions as values, for when I am adding 2 + 2 I am really saying 4, when I am adding 3 + 3 I am really saying 6, and so on. A = A. B = B. Since there are no tragic (or happy) surprises in coherency, I can rest peacefully at night, knowing that I am in control. And I can also wake up empowered for I know nothing can betray me. And since I am in control, I have more volition: I can handle functions as values, passing them as arguments, receiving them as outputs, composing them with and in others, because they always result in the same values for a given set of arguments—values in disguise.

 

4. Recursion

And thus Ouroboros rebirths, for when a function sees other functions as values, she realizes that she, too, is a value. “I map values from domain to range,” she tells herself. “But, like my kin, I myself am a value. Does that mean I can map myself into myself?” She becomes recursive, but like light, it is not a matter of how to entice motion, but how to stop it. No wonder recursion has the potential to overrun stacks, for dynamism itself is energy unlimited. But, like life, nothing can last forever; everything must have a limit, otherwise catastrophe ensures at the endless expenditure of limited resources. And so Ouroboros must be stopped by the human hand, impairing her to a base case, the last value she shall become, against her wishes to become one with infinity, cycling into eternity. 

 

References

Hinsen, K. (2009). The promises of functional programming. Computing in Science & Engineering, 11(4), 86-90.

Comentarios