|
Aaron Rosenzweig / Chat 'n Bike e: aaron@chatnbike.com t: (301) 956-2319 |
|
|
|
On 14 May 2014, at 13:27, Carlo <snoobabk@gmail.com> wrote:HiObviously this all depends on context and what is trying to be achieved ;)In certain cases all we want to do is ensure the container is not modifiable but don�t mind access to the held objects within. if the internal data is immutable (e.g. a representation of an error) then we don�t care if they have access to this data but we may care that they modify the collection that holds these objects. You then need to weigh in with a pro/con of using unmodifiable collections versus a copy; most of the time a copy is all you need as the collections will be small.If the context requires for some (odd) reason complete immutability and you�re happy to pay the price in terms of space/time or additional complexity then there are other solutions from deepCopy, to something like Worlds (http://www.vpri.org/pdf/tr2011001_final_worlds.pdf , http://www.vpri.org/pdf/m2013002_experiments.pdf ) or maybe some weird use of software transactional memory.We did an experiment with read-only references some time ago:The idea is that we hacked the VM to have references-as-objects that can override behaviour transparently.Marcus