• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDictionary mutability test
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSDictionary mutability test (From: "email@hidden" <email@hidden>)
 >Re: NSDictionary mutability test (From: "email@hidden" <email@hidden>)
 >Re: NSDictionary mutability test (From: Sherm Pendley <email@hidden>)
 >Re: NSDictionary mutability test (From: "I. Savant" <email@hidden>)
 >Re: NSDictionary mutability test (From: Adam Leonard <email@hidden>)

  • Prev by Date: Re: Core Data request predicates and to-many relationships
  • Next by Date: Re: NSDictionary mutability test
  • Previous by thread: Re: NSDictionary mutability test
  • Next by thread: Re: NSDictionary mutability test
  • Index(es):
    • Date
    • Thread