• 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: substring return a new string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: substring return a new string?


  • Subject: Re: substring return a new string?
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 18 Mar 2004 21:28:48 +0100

Marco,

On Thursday, Mar 18, 2004, at 21:11 Europe/Prague, Marco Scheurer wrote:

It may be safe, but it does not make it right. What you do is advertising a mutable property of your object,

No I am not--not in the sense at least I understand "property". Does, for example, -[NSFileManager subpathsAtPath:] return a "file manager property"? This case, I am just _generating an object on the user's behalf_. The object happens to be mutable. I can see absolutely no problem in that.

It is quite possible in some conditions, had I return an immutable object, the vast majority of usages would look like this

NSMutableArray *ma=[[[foo someArray] mutableCopy] autorelease];

and do not please forget that (as implied by the previous discussion) we are speaking here about a bottleneck (well, a situation where speed and memory footprint are important).

and the user could legitimally think that he can modify this property.

So he can. Only it is not a property.

This would be extremely bad design IMHO (and anyway, returning mutable things, even ivars of your object, is bad in general).

Returning mutable _ivars of your object_ is bad in general (albeit there are rare cases when it is right), no argument here.

Returning mutable _generated objects_, on the other hand, is not bad in general. At least I don't see any reason why it should be (but for the limitation for future changes in the class implementation, which is pretty weak a reason).
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.


  • Follow-Ups:
    • Re: substring return a new string?
      • From: Alastair Houghton <email@hidden>
    • Re: substring return a new string?
      • From: Marco Scheurer <email@hidden>
References: 
 >Re: substring return a new string? (From: Marco Scheurer <email@hidden>)

  • Prev by Date: Key codes and characters in NSEvents
  • Next by Date: Re: substring return a new string?
  • Previous by thread: Re: substring return a new string?
  • Next by thread: Re: substring return a new string?
  • Index(es):
    • Date
    • Thread