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: Ondra Cada <email@hidden>
- Date: Mon, 7 Jun 2004 15:31:44 +0200
Marco,
On 7.6.2004, at 14:57, Marco Scheurer wrote:
>
Yes but the copying of the keys brings no advantage to the user, and
>
only adds burden:
>
>
(1) if the key is immutable then copying is useless (and often
>
defaults to retain anyway)
>
(2) if the key is mutable then
>
(2a) if its value does not change between storage and retrieval then
>
copying is useless
>
(2b) if its value change between storage and retrieval then you will
>
not find your object anyway.
>
>
So we have a protection that works only when it does not matter.
(2c) it's the actual value you are interested in, but it just
happens--for some out-of-your-control implementation reasons--to be
represented by a mutable string.
Say, you got a dictionary which saves user/password pairs, and an
NSTextView is used for the user name: since its -string happens
(happened when I last checked for sure) an NSMutableString, you have to
copy so as the dict works as intended.
Now, let's not argue over whether it is better in such a case to copy
at the dictionary level (as Cocoa creators and me happen to think) or
above it, at the controller level (as you and Marcel are so profoundly
sure). Just I wanted to point out there *is* a 2c which needs the copy
*somewhere*. I may add in my personal experience such cases happen
*very* often, but you can say it's my bad programming style ;)))
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
[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.