Re: cocoa-dev digest, Vol 2 #2711 - 14 msgs
Re: cocoa-dev digest, Vol 2 #2711 - 14 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #2711 - 14 msgs
- From: John Randolph <email@hidden>
- Date: Tue, 29 Jul 2003 14:15:15 -0700
On Monday, July 28, 2003, at 6:58 PM, Greg Titus wrote:
On Monday, July 28, 2003, at 5:58 PM, Chris Purcell wrote:
Fritz Anderson wrote:
NSString * result = [ofProcessingObject processedString];
[ofProcessObject release];
NSLog(@"The result is %@", result);
I am entitled to assume that result has not been disposed-of, am I
not?
Yes. In this case, indubitably. Bad coding in OF, or bad choice of
method name. It translates as "the string that results from
ofProcessingObject's processing", not "the <property> of
ofProcessingObject". I'd say this is the exception that proves the
rule.
I'll interject here, since I may very well make coding changes in OF
based upon this thread. :-)
First, since there is no processedString method in OmniFoundation, I'm
assuming that Fritz was making a generic example and not talking about
a specific method name. Thus, "bad choice of method name" doesn't
really apply here.
If you saw these methods (some of many in OF):
- (NSString *)stringByUppercasingAndUnderscoringCaseChanges;
- (NSString *)stringByRemovingSurroundingWhitespace;
- (NSString
*)stringByCollapsingWhitespaceAndRemovingSurroundingWhitespace;
- (NSString *)stringByRemovingWhitespace;
- (NSString
*)stringByRemovingCharactersInOFCharacterSet:(OFCharacterSet
*)removeSet;
- (NSString *)stringByRemovingReturns;
- (NSString *)stringByRemovingString:(NSString *)removeString;
- (NSString *)stringByPaddingToLength:(unsigned int)aLength;
- (NSString *)stringByNormalizingPath;
Would you expect that calling, for instance,
-stringByRemovingWhitespace might return the same string object if
there was no whitespace in it?
I would not be surprised by that. I would also not be surprised if I
got back an autoreleased copy of the original string object.
Should it be retained and autoreleased because this isn't a property
of the original string? Or would it be preferable just to document
this possibility and avoid the autorelease?
I know now what Fritz' expectation would be (by the way Fritz, did you
ever report this as a bug? I don't remember seeing anything about
it...)
Anyone else have an opinion?
What I would expect from any instance method returning a (potentially)
modified string like this, is that the value returned should be
immutable, and that I shouldn't have to release it.
BTW, it's not clear to me what the difference is between
-stringByCollapsingWhitespaceAndRemovingSurroundingWhitespace and
-stringByRemovingWhitespace would be. By "collapsing", do you mean
shrinking all whitespace to a single space character?
-jcr
_______________________________________________
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.