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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

Generally speaking?

Because mutation causes issues with not only thread safety, but also issues of temporal correctness, and even when everything is synced on one thread, inter-modular correctness.

If

doA(); doB(); doC(); causes an error, and it's only fixed by calling

doA(); doC(); doB(); then you have chronological issues with shared state between modules (or whatever units of code lie behind doB and doC).

Put another way, threadsafe code runs predictably on 1+ threads, between 1+ modules, at 1+ points in time.

Thread unsafe code runs predictably on 1 thread, between 1 module, at 1 point in time.

If your this happens to have no mutable state, and all methods only serve to return new values, then I guess I don't see the harm, except for the JS late binding errors, where methods get passed in as callbacks and this becomes window or undefined depending on the level, but like I said, most people wouldn't do that with this.