DEV Community

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

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.