DEV Community

Discussion on: Immer vs Ramda - two approaches towards writing Redux reducers

Collapse
 
chasm profile image
Charles F. Munat

The problem with Immer is that it purports to give you the benefits of functional programming without having to learn functional programming. You can keep using all your old, impure, mutable techniques, but Immer will babysit for you and clean up your messes. This is infantilizing.

I much prefer Ramda because it means that I have to think like a functional programmer -- something that is much easier than most OOP programmers believe. If they hadn't learned OOP first, they wouldn't have so much trouble learning FP. It requires a lot of unlearning.

But when I teach beginners, I always start with FP and only FP, and I often use Ramda. Then I have them reimplement the Ramda functions in vanilla JS -- it's not difficult at all. In the end, they understand immutability, referential transparency, recursion, and more and it just comes naturally to them.

For me, Immer is a code stink.

Collapse
 
fkrasnowski profile image
Franciszek Krasnowski

The problem with Immer is that it purports to give you the benefits of functional programming without having to learn functional programming

Most software developers are lazy. It's easier to just upgrade your existing tool a little to fix some problems than to learn the new ecosystem in which this problem does not exist. You can make great language but most devs who know C will choose C++.

If it comes to me I like how it's done in Rust where you can create mutable references inside a function. In JavaScript similar functionality can be achieved by just making deep copies inside the function:

const fn = arr => {
   let nextArr = deepCopy(arr)
   nextArr[1] = 2
   return nextArr
}
Enter fullscreen mode Exit fullscreen mode

Still Immer makes it terser:

const fn = produce(arr => {
   arr[1] = 2
})
Enter fullscreen mode Exit fullscreen mode

I like the explicitness of this "mutation". Immer can be handy when you have to deal with some stateful problems - it encapsulates your mutating logic. And that's what most functional languages do - hiding state from a developer by for example switching tail recursion to iteration.