←back to thread

191 points jwilk | 1 comments | | HN request time: 0s | source
Show context
perrygeo ◴[] No.46232229[source]
Python discovers immutable data, and gets it wrong. Frozendict is a blunt instrument - instead of a mutable free-for-all, it just locks the data for the entire lifecycle. Brace for the wave of code littered with deep copies, proudly proclaiming how functional it all is.

If you want real immutable data structures, not a cheap imitation, check out pyrsistent.

replies(2): >>46232356 #>>46232421 #
cylemons ◴[] No.46232421[source]
How else would you "modify" immutable data other than by copying it?
replies(3): >>46232514 #>>46232538 #>>46238746 #
1. tylerhou ◴[] No.46238746[source]
Basically, a proxy. You don't need to deep copy; you just need to return a proxy object that falls back to the original dict if the key you are requesting has not been found or modified.

Functional data structures essentially create a proxy on every write. This can be inefficient if you make writes in batches, and you only need immutability between batches.