Re: NSDictionary mutability test
Re: NSDictionary mutability test
- Subject: Re: NSDictionary mutability test
- From: "I. Savant" <email@hidden>
- Date: Mon, 8 Dec 2008 18:40:55 -0500
On Dec 8, 2008, at 5:15 PM, Adam Leonard wrote:
I agree that it is definitely wrong to declare method as returning a
mutable object, and actually returning a immutable object instead.
But is it really true that it is wrong to do it the other way around?
I absolutely cede that point. I admit I was mostly thinking of the
'advertise-mutable-but-return-immutable' situation more than the other
way around.
But ... :-) ... I believe it is sloppy and imprecise. For this
reason, I consider it bad programming. Nothing should be ambiguous
unless the ambiguity is necessary (for which "id" exists).
I would not argue that you should return [[mutableDict copy]
autorelease] ... this has performance implications that outweigh
"precision".
None of the above, however, detracts from the original point I
jumped in on: asking if a collection is mutable is of limited utility
precisely because you should already know what you're getting and
controlling flow based on mutability only adds unnecessary complexity
to the logic of your code.
I'm pretty sure I have seen the Cocoa frameworks doing this.
I've also seen Cocoa crash. And miscalculate dates. And do a number
of other unsavory things over the last decade. I'm not saying this is
one of those cases (ie "it's a bug"), but "Cocoa does it" doesn't
automatically classify the behavior as unassailably correct. :-) It's
likely that the developers also decided precision wasn't worth the
[[mutableDict copy] autorelease] overhead, given the relative
harmlessness of "the other way around" as above.
< gets down off Idiot Soap Box™ >
--
I.S.
_______________________________________________
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