Re: Copying, hash, and isEqual:
Re: Copying, hash, and isEqual:
- Subject: Re: Copying, hash, and isEqual:
- From: Brent Gulanowski <email@hidden>
- Date: Mon, 7 Jun 2004 14:54:46 -0400
On Jun 6, 2004, at 8:42 PM, Marcel Weiher wrote:
>
>
> - if object (A) and object (B) are to be used as a key in a
>
> dictionary, then -hash and -isEqual: need to be overridden
>
> accordingly.
>
>
Which isn't documented. In fact, the documentation for -hash
>
recommends the *opposite*. But that's a very minor issue...
>
Maybe that's more of an issue than you're willing to admit in terms of
this broken sample code?
Marcel, your argument is certainly legitimate although I don't know
that it's strong enough to override the counter-arguments.
The fact under debate is whether copying of keys is a good idea in the
case where a key may not override -hash and -isEquals:
The apparent disconnect between the documentation for the NSObject
implementation of -hash and the documentation for NSDictionary may be
more important that the actual implementation. NSDictionary relies on a
certain minimally functioning object as a key in order to do its job.
If it did not copy keys, then the default implementation of -hash and
-isEqual: would make NSObject instances ostensibly sufficient as keys,
although they would be deficient in every other way and basically be
useless between program runs.
It is clear (I argue) that the default implementation of -hash is the
problem, not NSDictionary. -hash is broken vis a vis NSDictionary, but
this is documented. Because identity of an object depends on a
legitimate implementation of -hash -- one which must transcend
incidental temporary state like the location in memory -- your sample
class is brain-damaged and does not qualify as a valid class for keys
for NSDictionary.
To get back to your argument: Any object should be a sufficient key for
NSDictionary; it is not, and you argue that this is the real problem: a
fundamental design flaw. In which case, your sample code is not a
sufficient demonstration of the bug, I must say. You must implement a
legitimate -hash, say, to use the time of the object's creation or
something else important that would get stored but not carry over to
copies, to get around these piecemeal counter-arguments about
NSObject's broken implementation of -hash. Is that possible?
The fundamental disagreement is over the legitimacy of requiring that
key objects be functional even after copying. To make your case you
really need to show that copying can break some required aspect of a
key.
You have argued that copying to prevent corruption of the dictionary
due to changes to mutable retained keys is an illegitimate practise in
light of the infrequency of the problem, however you have not
successfully argued for a good estimate of that frequency, nor an
alternate solution to prevent it in even those rare cases.
In opposition you provide a case where copying does not prevent
corruption of the dictionary, but this case could readily be argued to
also be very rare (probably rarer than the counter-case), to in fact be
deliberately in violation of the documentation, and to be predominantly
theoretical in nature. I'm not against theory, but the design choices,
including what you consider an inadequacy, were made for (assumedly)
practical purposes. I'd like to see other, more meaningful examples of
why the current design is impractical, as opposed to simply inelegant.
I find this all very fascinating but would dearly love to see a
resolution and a cessation of meaningless bickering.
Cheers,
--
Brent Gulanowski email@hidden
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.
References: | |
| >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>) |
| >Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: "Louis C. Sacha" <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Nat! <email@hidden>) |
| >Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>) |
| >Copying, hash, and isEqual: (From: "b.bum" <email@hidden>) |
| >Re: Copying, hash, and isEqual: (From: Marcel Weiher <email@hidden>) |
| >Re: Copying, hash, and isEqual: (From: "b.bum" <email@hidden>) |
| >Re: Copying, hash, and isEqual: (From: Marcel Weiher <email@hidden>) |