News for hackers. Stuff that matters.
Re:Immutable Data Structures That Are Compatible with Normal... by Y7ZCQtNo39 on Saturday August 12, 2017 @01:28PM (#14998862)
I've been using this:

https://github.com/guigrpa/timm

The onus is on the developer to actually ensure immutability, but as long you're always mutating via the library functions, you should be fine.

I've used more serious solutions, like Immutable.js, but I prefer this instead. The wrapper functions in Immutable.js, in my experience, aren't worth the trouble.

Re:Immutable Data Structures That Are Compatible with Normal... by kasbah on Saturday August 12, 2017 @01:35PM (#14998901)
Well if the onus is on the developer it kind of defeats the purpose no? As you likely know seemless-immutable also has a "production" mode that has better performance but doesn't ensure it. That seems like a good compromise to me, so that at least during development you get errors when things are being mutated.

The benchmarks in the Timm readme are interesting though. I would like to see a benchmark of seamless-immutable in production mode added to compare.

Re:Immutable Data Structures That Are Compatible with Normal... by Y7ZCQtNo39 on Saturday August 12, 2017 @02:56PM (#14999355)
It doesn't defeat the purpose. It only mutates if there is actually a change to the data structure. When used properly, timm works great.

The (potential) problem is that it is still possible to mutate objects without the use of timm's utility functions.

If you value the performance benefits (no penalty for freezing objects since timm doesn't do that), and understand that to get the benefits, you must only mutate objects using timm, choose timm.

If you value the additional safety other libraries provide, then absolutely use one of those. It all depends on the use case.

You don't need to freeze objects if you are doing it properly. You could even do static analysis to know (by checking to see if you're reassigning object properties, etc).