Re: substring return a new string?
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.