Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is one of the reasons I tend to consider "immutability" a bit of a misfire. A completely understandable one, an inevitable one, and one I am not at all critical of, but it is not the way to build systems. Mutability is a fundamental fact of life. The key is control over mutability. Uncontrolled mutation is the problem. Code needs to know that if it reaches for a value of "x" now, three lines later it will not be different unexpectedly. Code needs to be able to know when it is "updating" with the rest of the world and thus all the old guarantees are gone, but whatever value it sees now is now reliable until the next sync. Uncontrolled mutability is the problem. It is difficult, and arguably simply impossible, to write correct code when your foundation is constantly unobservably shifting. Even single threaded code becomes a monster if you call a function and it starts scribbling all over whatever variables it feels like.

Transactional isolation and Rust's borrow checker are in my opinion much closer to what we are really reaching for.

Immutability is still a nice simplification of those things, though. Both of those things are quite difficult to work with. Full, true transactional isolation tends to deadlock at the drop of a hat, and Rust's borrow checker is much more complex conceptually than immutability. It can be a reasonable choice to work with full immutability in some circumstances.



I don't think anybody (even us Haskell weirdos) are clamoring for full immutability of anything. For data structures it's AMAZING unless you really cannot live with a log factor, but that's neither here nor there.

Anyway, for me it's all about controlling and sequestering off (shared) mutability... and -- at a slightly higher level of abstraction -- capabilities given to random bits of code. Being able to conclusively say that a function "foo" can only perform operations on a "User repository" (or whatever) and not randomly go prodding the database directly is amazing.

(Think of "mut" as a capability and you'll probably get the gist of what I mean. It's just a bit more general.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: