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: Marcel Weiher <email@hidden>
- Date: Mon, 7 Jun 2004 17:19:38 +0100
On 7 Jun 2004, at 14:31, Ondra Cada wrote:
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.
Yes. This was at the back of my mind, but I didn't have it in focus
quite as clearly.
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.
Then you need to make a copy, completely irrespective of wether you are
inserting this value into a dictionary (as key or value) or doing
something else with it.
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.
No. *You* have to copy so that user/password works as expected. With
what you have just suggested (just shove the -string into the
dictionary and let the dictionary take care of making safe copies), you
have just implemented a HUGE bug (and I can't believe you are actually
suggesting this):
Assuming you are storing user -> password, you have just implemented a
system where all users are going to have the same password, which will
continue to change.
Do I need to explain why this is so?
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)
Well, I am still hoping that the huge gaffes your assumption keeps
causing you to make will start you considering that this is *precisely*
the issue to argue over, and that hoping that someone else has taken
care of this for you is just a fantasy.
or above it, at the controller level (as you and Marcel are so
profoundly sure).
Well, the difference is that our way works and yours doesn't...
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 ;)))
Yes. If you rely on some "magic" to make those sorts of decision for
you, that *is* atrocious programming style.
Cheers,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
1d480c25f397c4786386135f8e8938e4
_______________________________________________
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.