Re: Ugly bug in Foundation, beware!
Re: Ugly bug in Foundation, beware!
- Subject: Re: Ugly bug in Foundation, beware!
- From: Nicko van Someren <email@hidden>
- Date: Thu, 3 Jun 2004 17:39:02 +0100
On 3 Jun 2004, at 17:01, Ondra Cada wrote:
On 3.6.2004, at 17:48, Marco Scheurer wrote:
This is not a bug: there are cases where you want to make a deep copy,
but they should be rare, and only you know what they are.
Well, paint me a newbie. What are the archetypal usages for copy in
Cocoa? I'd say
- dictionary keys, sets: deep copy needed not to break hash when the
guts change, OR you stick with the current nonsense of all two-item
arrays in one hash, which is a disaster for efficiency;
Dictionary keys are indeed a place where you want a real copy, for
exactly the reason you state, and as it happens the keys are indeed
copied, while the values are simply retained again.
- undo snapshots: deep copy self-evidently needed, or you undo back to
later state than the proper one;
There are plenty of ways to implement undo without taking a snapshot
(most of which are more memory efficient). If you must take a snapshot
then what you are really doing is preserving the state for reuse at a
later time, which is called archiving, so you should probably use
something like NSArchiver.
- has-a setters: deep-copy self-evidently needed, or your has-a
invisibly turns into a shared object.
Any other arguments?
Actually I think the one that Marco made at the top, that only you know
when it is appropriate to deep copy the data structures used by your
program, coupled with my previous point that only you know when it is
_possible_ to deep copy your data, should be sufficient arguments.
Nicko
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.