Comment

Comment by jmull

> A lot of people think that functional programming is mostly about avoiding mutation at all costs.

People should try to stop thinking of mutation as something to be avoided, and start thinking of it as something to be managed.

Mutating state is good. That's usually the whole point.

What's bad is when you create "accidental state" that goes unmanaged or that requires an infeasible effort to maintain. What you want is a source of truth for any given bit of mutable state, plus a mechanism to update anything that depends on that state when it is changed.

The second part is where functional programming shines -- you have a simple way to just recompute all the derived things. And since it's presumably the same way the derived things were computed in the first place, you don't have to worry about its logic getting out-of-sync.

parent jmull 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton