On Dec 8, 2008, at 2:25 PM, [EMAIL PROTECTED] wrote:
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.

Is this a bit like the emperor's new clothes?
As long as everyone says its an NSDictionary then it matters not if its an NSMutableDictionary!
A sort of mutually agreed insurance.

Well... yes... but since you can't reliably differentiate between mutable and immutable, then it is difficult to tell if the emperor is clothed or not.

Objective-C is C with objects and C provides an infinite amount of rope. The implementation philosophy of the AppKit and Foundation is such that it tries to make not entangling yourself the most natural of coding pattern available. Given the great lengths that one would have to go through to determine behavior based upon mutable vs. immutable, the inconvenience keeps most from entanglement.

(A bit of trivia -- there were several major versions of Mac OS X released where NSDictionary instances *were* mutable.)

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.
This reminds me of the memory retain/release rules (if you alloc it you release it etc). If these points aren't already in the docs already then they wouldn't be out of place there.

A bug was filed to track documentation clarification: <rdar://problem/6428503 >

b.bum
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to