> > All of that kind of adds up to make it a distraction that's likely worse > than a dict subclass with __setitem__ overridden (if that's the > behaviour you want). It's a fantastic data structure for when you need > it, but it's one that deserves to be researched and understood before > simply dropping it into your code. An optional package is a perfectly > good place for it. >
I agree with this. I just want to explain a little bit about why we want to mutate an immutable map. Immutable data structures have some nice features. Because of its immutable nature, immutable data structures are inherently thread-safe so much safer to use in a multi-thread environment. And it can be much faster to find the differences between two immutable data structures because we can replace != with is not , therefore quickly rule out all unchanged data. The immutable nature is actually very powerful when you want to change a map(especially with nested maps in it) often, then need to find the differences in other places. It sometimes reminds me of git. With immutable data, we can keep every snapshot of data history in memory. Reduced memory usage is also important. I think immutable map and frozendict are actually two different data types because they have different intentions. The author of immutable.js gives a great talk about how immutable data structure is implemented and why it’s powerful. React.js actually relies a lot on immutable data structures. Here is the youtube link to the talk: <https://www.youtube.com/watch?v=I7IdS-PbEgI&t=1005s> https://www.youtube.com/watch?v=I7IdS-PbEgI&t=1005s There is also a CppCon talk about immutable data structure: <https://www.youtube.com/watch?v=sPhpelUfu8Q&t=412s> https://www.youtube.com/watch?v=sPhpelUfu8Q&t=412s
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/HJUY734PUZ3CMHF7SMLM27D63JRWH7RQ/ Code of Conduct: http://python.org/psf/codeofconduct/