4 ms·
Well, sure, but why would you want local mutable state? In some cases it's more efficient to alter transient data in place, but mutability makes it much harder
by weavejester 13y ago
Well, sure, but why would you want local mutable state? In some cases it's more efficient to alter transient data in place, but mutability makes it much harder (and usually less efficient) to effectively compose functionality.
I guess Java does make it seem like the opposite is the case; that it's easier to work with mutable data, and that immutability is just a needless restriction. However, in languages with lambdas and higher-level functions, local mutability is rarely required, and becomes a hindrance rather than a help. Just look at how many times "options.dup" turns up in Ruby code: https://github.com/search?q=options.dup&ref=cmdform&type=Code https://github.com/search?q=options.dup&ref=cmdform&type=Cod... . It's an annoying pattern in Ruby to work around the lack of immutable maps in the core language.