(A honest question, I start to think that I'd like to learn more on this language)
So the mutable (or is it “volatile”?) environment is there, but you explicitly know when and where you interact with it.
Congratulations, nobody is going to sneakily update an object on you, but also, nobody knows about your updates either.
It’s not a worthwhile trade off given the massive extra work it causes.
The whole idea of CQRS is to build separate (segregated) pathways for updates. Immutable passing plays extremely well with CQRS. The alternative is the complete clusterfuck that is two way data bindings (e.g. out of the box angularjs)
When you're immutable, you can still delete or replace data.
I agree that immutability is a tool. My issue with it is when you treat it as a rule.
I've seen Heisenbugs where some random code calls a setter on an object in a shared memory cache. The setter call was for local logic - so immutable update would've saved the day. It had real world impact too: We ordered a rack with a European plug to an American data center (I think a human in the loop caught it thankfully).
Also, how often do you even use mutability really? Like .. for what? Logic is easier to express with expressions than a Rube Goldberg loop mutating state imo.
Having the ability to do so generally is tablestakes for being an intermediate professional programmer imo. In university, I had to draw diagrams explaining the state of the C stack and heap after each line of code. That's the same thing. And I was 19 lmao. It's not hard.
Maybe you're referring to space leaks? I've run into like 2 in my ten year Haskell career, and neither hit prod
I've actually seem more Go and Java space leaks/OoM bugs hit prod than Haskell - despite having fewer total years using those languages than Haskell! Nobody blamed the language for those though :/
I suspect, given the real, actual measurements, the number of difficult to deal with bugs is pretty consistent between immutability and mutability. Actual measurements does not support claims of “easier to reason about”, or “reduced bugs”.
>how often do you use mutability
Whenever something should change and I don’t specifically need functionality that immutability might provide (literally 99.99999999% of every state change).
Immutability has some big advantages for pure logic, such as allowing containers to be treated as values the same as numbers. And efficient immutable data structures of all kinds are commonplace now.