DEV Community

Discussion on: Learning Functional Programming

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

If you're looking for practical experience that you can use in your current projects, then look towards the functional aspects of your current language. Functional programming is a paradigm, it does not define a language.

You are looking to using the high-level constructs like pure functions and high-order functoins. You want to learn about immutable data structures, recursion and things like lambdas and closures.

JavaScript, Python, and NodeJS, among those I know, all offer a good assortment of functional programming constructs. C++ does as well, but it's syntax can be a bit daunting. I'd likely start with Python since I've seen people use it's functional aspects to wonderful effect while coding (during interviews I've done).

Collapse
 
tobias_salzmann profile image
Tobias Salzmann

For me, it seems Python is an odd choice to learn functional programmming. I've recently picked it up for a project, and I do my best to use it in a functional way, but it keeps throwing obstacles. For example, the 2 primary data structures, lists and dictionaries are mutable.
There is a package called toolz that helps quite a lot, but compared to something like ramda for Javascript, it feels very shallow and without a clear concept.
It's main mode of failure also seems to be exceptions, which kind of makes it harder.
Why do you think it's a good starting point?

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

I said for practical experience. If you're already using Python on a project you can start learning functional constructs in your actual code.

Paradigms are only useful in combination with other paradigms as well, so it's good to learn how to use them together. In this case it's also helpful to learn the concepts when presented with a language that isn't strict about its constructs.

Exceptions are totally fine in the functional paradigm. Some languages choose to use Monads instead, but nothing about exceptions breaks the functional model. In my experience monads are more confusing, and less helpful than an implicit error model.

Thread Thread
 
tobias_salzmann profile image
Tobias Salzmann

I think we're talking about different things here. To be clear, I absolutely agree that functional programming concepts can be applied to any other language that does not feature it as one of their strongest paradigms. An generally, it's a good idea to do that to some degree, highly dependent on general language idioms.
In order to learn those concepts though I would recommend going for a language where those concepts are somewhere between important and fundamental. And that includes fundamental concepts like Monads, ADTs and referential transparency.

Whether exceptions are fine or not within FP really depends on the definition of both. I've seen monads being overused and annoying, but I've also seen them restoring maintainability for large codebases. For asynchronous code, they are very valuable.