loading...

Discussion on: OOP vs Functional Programming

Collapse
leob profile image
leob

Interesting how some people (years ago) predicted FP to become "the next big thing" but we're all still waiting for it to really take off. Frameworks like React have a bit of an FP feel and replacing loops with map/filter/reduce in Javascript have become somewhat popular, but the top 20 "most popular" programming languages doesn't contain even one FP language.

I'd be open to embracing FP and go all the way with it, at least for some projects, but it looks like it ain't happening yet (if ever). Still waiting for FP's "big moment", after all those years it's still "niche".

Collapse
macsikora profile image
Maciej Sikora

20 most popular languages are mostly multi-paradigm 20+ years old like Java, C, C++, JavaScript., Python, PHP. Till 2010 there was no hype for FP, therefore languages FP features were even not discussed, but they were there. JavaScript for instance was always lamda language, there were no classes, you had higher order functions and closures from beginning.

The current state of art is that every of mainstream languages has FP features, even Java considered as strictly class OOP language has for example lamdas/closures and Optional. C# language query LINQ was inspired by Haskell and static type functional languages. Promise in JavaScript is monadish and inspired by FP. Array, List structures almost in every language have higher order functions like .map, .filter and .reduce.

From the new languages. There is no new language I am aware of which doesn't have FP features. Take Rust as an example. Rust has lamdas, higher order functions, Optional and for example Vector in Rust has a lot of similarities to List in Haskell. You can write FP code in Rust and even it is hard to not.

Pure FP is still a niche. So in terms of what is not happening, it is popularity of pure FP. So languages without side effects like Haskell or Elm. I feel here the learning curve and the difference in programming is huge, that is why it is hard to grasp concepts from such languages. IMHO expression based languages are the future, but I am not sure if full purity is, maybe algebraic effects will change that. Will see.

Collapse
leob profile image
leob

Rust is very interesting, I think among the "popular" languages it comes closest to being an "FP light" language. I've studied it a bit and it reminded me a lot of Haskell with its algebraic data types.

Of the major "popular" languages I guess that Javascript has the most FP potential.

However if I'm not mistaken you could say that Go is an outlier, the fact that it doesn't support generics mean that map/filter/reduce are as good as impossible, you're more or less forced to program everything with procedural loops.

But for the rest, if you look at the top 20 languages what surprises me is how 'conservative' it is, people stick to what they know, ancient C and C++ are still high up there, really innovative and ground-breaking languages aren't making it into the top 20.

I know that some FP features are making it into most popular languages, Javascript is a language with a good deal of that, however only a pure FP language will force you to think with a genuine FP mindset, barring that people will adopt some of the map/filter/reduce style but that's about it.

In other words, regarding FP breaking into the "main stream" I'm not holding my breath.