zackoverflow

Functional Programming's Influence on Mainstream Programming

Just how much of mainstream programming has been influenced by FP?


I have been infatuated with functional programming for some time now. What first made me consider learning more about it was its influence on React/Redux and the ecosystem surrounding it. I particularly wanted to know why React emphasized constraining side-effects to the useEffect hook and why Redux had such an emphasis on immutability.

Even if you haven’t been exposed to React/Redux, you still have felt the effects of FP’s influence. The most obvious example, higher-order functions and those handy array functions that every language has now (.map(), .filter(), .reduce()) were present in Lisps in the 70s — years before mainstream languages.

If you have used an OOP-language, you’ve probably encountered generics. They’re extremely helpful and greatly reduce boilerplate. Generics were introduced to Java in 2004, 26 years after they were introduced to FP through polymorphic types in ML (ML == Meta Language, not to be confused with machine learning). In fact, Java’s implementation of generics was directly influenced by ML.

But the roots go deeper, do you like manually managing your memory? Probably not. You’ve most definitely used a language with a garbage collector. Well, did you know that garbage collection was invented in the 1950’s by John McCarthy for Lisp? That’s right, for 40 years — until Java entered the scene in the 90’s — mainstream programmers were manually managing memory… while every FP language had a garbage collector.

This gives us even more context for Paul Graham’s essay, Beating the Averages. You know, the one where he talks about blub programmers. It is even more clear why he felt so productive in Lisp in the 90’s. He had garbage collection, those handy array functions, dynamic typing… all while most startups were using C, C++, Fortran, Pascal and having to manually manage their memory!

If you know Rust, there are a great deal of concepts directly influenced from FP. Enums are algebraic data types from ML and its derivatives, traits are Haskell’s typeclasses, and the borrow checker is inspired by affine type systems which dates back to the 80’s from the language Clean.

These are just a few examples I felt were the most profound, and you can find many more examples of FP’s influence. But from what I’ve shown, it’s clear that FP languages have historically been at least a few decades ahead of the mainstream. That seems like a pretty strong reason to learn an FP language, at the very least you have the opportunity to bring these new ideas back into imperative languages and improve them.