Re: NSDictionary mutability test
Re: NSDictionary mutability test
- Subject: Re: NSDictionary mutability test
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 08 Dec 2008 13:54:41 -0800
On Dec 8, 2008, at 1:43 PM, email@hidden wrote:
This decisions was purposeful, explicit, and intentional.
I find this an interesting point. Why was such a decision made? It
seems counter intuitive.
Performance
An NSMutableDictionary instance can be returned from a method declared
as returning (NSDictionary*) without risk that the client is going to
go and change the contents behind your back. If "test for mutability"
were common, then all kinds of methods across the 'kits would have to -
copy the return value and, potentially, deeply.
Simplicity
What does "mutable" even mean in the case of a collection? If an
NSArray of NSDictionaries is "mutable", does that also mean the
NSDictionaries contained within are mutable? The current design
point is that pretty much everything is immutable unless (a) you
specifically created a mutable data structure or (b) the 'kit
explicitly returned a mutable data structure.
Reliability
Having lots of "if (mutable) this else that" decision points would
reduce the reliability of code in that it would increase the testing
load. Example: Unit tests would have to explicitly test the code
for both the immutable vs. mutable variants. And that doesn't
consider the "mutable container vs. immutable contents" potential
myriad of combinations.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden