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

So you've just made the internal state of your program inconsistent? Why is this supposed to be good?


No, it's not inconsistent. If you want to call this inconsistent, then the mutable version of the program is also inconsistent.


It can't be inconsistent. You've got one copy of the data in memory, everything uses that, everything sees the same thing.

What's the use case of all this copying and shunting stuff around and consuming massive amounts of memory?

What kind of programs would you write that would benefit from this?


> It can't be inconsistent. You've got one copy of the data in memory, everything uses that, everything sees the same thing.

Wrong. For instance, state can be stored in locals. Two threads accessing the same structure, one reading and one writing, the reader loads some state into locals and the writer then invalidates that state in the middle of the reader's computation, and the reader proceeds to computing a result mixing old state and new state thus leading to inconsistency. This ABA problem is well known and it just can't happen if the structure is immutable. And this doesn't even go into cache coherency issues.

I frankly don't think you appreciate the number of hazards just making data structures immutable actually addresses, and given you don't seem aware of the hazards implicit to mutable data structures, I suppose that's not surprising.

> What kind of programs would you write that would benefit from this

Pretty much every single program that accesses a relational database benefits from this. There are a few of those around n in case you didn't know. Perhaps you've heard of multiversion concurrency control?


Concurrent programs where several threads read the same stream of data. For instance.

But a more common case is how I get my records from my db. Only the ORM can create those DB record for me ( because I set it up that way )

When I return a response; I compose another immutable response object.

And only my service layer can don that. ( it won’t compile elsewhere)


> everything uses that, everything sees the same thing.

Don't you use scope? I don't think I use more than 1 or 2 global variable per system.




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

Search: