Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
- Subject: Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
- From: Marco Scheurer <email@hidden>
- Date: Mon, 7 Jun 2004 16:20:56 +0200
On Jun 7, 2004, at 1:04 PM, Patrick Machielse wrote:
The design bug is in your MyObject class, which creates copies which
are not
'equal', not in NSDictionary.
And please let me also point out that NSSet is implemented differentl,
i.e. unlike NSDictionary, which at least hows some inconsistency. IMHO
NSSet's implementation is "correct".
NSSet does not copy the objects: "Objects added to a set are not
copied; rather, an object receives a retain message before its added
to a set."
Like NSDictionary, NSSet depends on the hash and isEqual: methods:
"Objects in a set must respond to the NSObject protocol methods hash
and isEqual:. See the NSObject protocol for more information."
However, the documentation goes as far as saying this about storing
mutable objects: "Note that if mutable objects are stored in a set,
either the hash method of the objects shouldnt depend on the internal
state of the mutable objects or the mutable objects shouldnt be
modified while theyre in the set (note that it can be difficult to
know whether or not a given object is in a collection)."
This totally contradicts all the arguments put forward so far in favor
of copying the keys in NSDictionary! You could argue that "the hash
method of the objects shouldnt depend on the internal state" is wrong
but does anybody want to come out in favor of copying objects in
NSSets? If not, why should keys be copied in NSDictionary?
All quotes are from :
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSSet.html
marco
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
_______________________________________________
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.