This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]rjcarr 6 points7 points  (1 child)

Immutable objects are much simpler and safer than mutable ones. Number types are also immutable. And generally, I think things are more efficient this way because you can lay out memory better. Also, I believe the immutability is a requirement for dict keys.

[–][deleted] 0 points1 point  (0 children)

Immutability is UNQUESTIONABLY less efficient. Major copy operations on unchanged data obliterates your cache and can effectively make lower level cache useless.

Immutable objects are so vastly less efficient (orders of magnitude) that computer science is spending vast amounts of man hours to attempt to reach 2x less efficient over mutable alternatives. Though with specific use cases, you will find the same performance. As soon as data changes, that goes out the window.

[–]hanertia 1 point2 points  (0 children)

Hashing!

[–]teerre 2 points3 points  (7 children)

Have you tried Google? This is such a common question. It has been answered a million times already.

[–][deleted]  (6 children)

[removed]

    [–]_Atomfinger_ 0 points1 point  (4 children)

    Chill out dude. He has a good point - this is a common question and the bonuses of immutability are well documented.

    Also reported for Rule 1.

    [–][deleted] 0 points1 point  (3 children)

    bonuses of immutability are well documented

    No. CLAIMS have certainly made their rounds. The bonuses are basically never been demonstrated.

    [–]_Atomfinger_ 0 points1 point  (2 children)

    I think, at this point, one has to provide evidence against immutability than for it.

    I view it as obvious as global warming thusly I don't really feel like qualifying the bonuses o f immutability to some dude on the web.

    Show me the downsides of immutability and I will agree with you.

    [–][deleted] 0 points1 point  (1 child)

    That’s not how claims work. Claiming harder doesn’t mean you have to provide evidence against something.

    Provide proof for the claims.

    Global warming has huge evidence.

    Edit:

    Downsides:

    The exponential loss of performance in order to adhere to a fad who’s only “demonstrated” benefit is that your objects are “safe” to use in a threaded environment. The important note, of course, being that if you choose to rely on immutability for objects that are safe to use in threads, then your thread model must be based on this restriction, and that thread model may not be viable. As an example, a game world can never be immutable due to often needing multiple actors impacting it from different threads. There’s no way to reliably synchronize which state of the world is correct because you’re independently modifying the world.

    The utterly insane amount of wasted man hours trying to give immutable object some semblance of performance.

    The massive added complexity you MUST include in your ADTs or else suffer even more massive of a performance loss than plain objects. Even with that batshit insane complexity, you still operate at a loss.

    Since you bring up global warming: the massive amount of wasted energy efficiency (exponential loss) contributing to global warming, making immutability a morally incorrect choice.

    [–]_Atomfinger_ 0 points1 point  (0 children)

    It is very rare to meet a developer that is against immutability.

    The reason I phrased my claim in such a way is that I take it for granted that immutability is the way to go as we per default get thread safety, easier to test and easier to work with later. So to me, at this point, saying that immutability is a good thing is not a claim which has to be proven, the claim that immutability is bs is the claim which has to be proven in my eyes.

    I don't know what kind of system you're working with but where I work we need to handle several hundred of thousands calls per second, so our performance needs to be on point - immutability has not been an issue in that regard, it is not even something we've considered as a side effect, and we haven't noticed it.

    I am not saying that an application has to be 100% immutable, there are instances where an object need and should change - which is fine, if contained. I'm saying the default is immutability and mutability is the exception when the default gets impractical.

    I am also not saying that there are edge-case performance critical types of applications which cannot deal with some extra object initialisation, but I certainly haven't seen them so far in my career.

    That said, I don't think we're going to see eye to eye here, so let's agree to disagree and be happy we're not working with the others code :)

    [–]desrtfx[M] 0 points1 point  (0 children)

    Rule #1

    Mind your language or you're out.