Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: Trivial/stu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 3780 of 3882
Post > Topic >>

Re: Trivial/stupid naming convention/cosmetics query - What would YOU do?

by Gregory Weston <uce@[EMAIL PROTECTED] > Jun 22, 2008 at 05:40 PM

In article <0amdnR0QzLH3XsPVnZ2dnUVZ_iydnZ2d@[EMAIL PROTECTED]
>,
 Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:

> Humor my OCD :) 
> 
> I have a method (as part of a category adding on to NSMutableData) I'm 
> trying to name in a "by the conventions" fa****on. It works fine - 
> nothing wrong there. I just don't like the way the method declaration, 
> or calls to it, look - it seems "klunky". So I wonder how other folks 
> would name it to make it more "elegant".
> 
> As an NSMutableData object loaded with arbitrary data, it needs to hunt 
> for two "magic strings" within itself, grab the data between those two 
> "magic strings", turn it into an NSString, and hand it back to the 
> caller. The "magic strings" might be practically any length, and it's 
> typical that they wont have any resemblance to each other - For 
> instance, the first one might be "Magic String 1 ", and the second might

> be " Blow It Out Your Ear". Given that, and the (admittedly contrived) 
> block of data that follows, I need the NSString that comes back from an 
> invocation of the method to be "This Is The Part I Want":
> 
> The data block:
> This is just some random garbage that I'm typing as an example Magic 
> String 1 This Is The Part I Want Blow It Out Your Ear and more data 
> follows that may or may not be related
> 
> For the moment, I've got the method coded like so:
> 
> // MyNSMutableExtensions.h
> // elide boilerplate #im****ts and other irrelevancies to save space
> @[EMAIL PROTECTED]
 NSMutableData (MyExtensions)
> - (NSString *)GetStringDelimitedBy:(NSString *)Delim1 
> EndingWith:(NSString *)Delim2;
> // elide more irrelevancies
> @[EMAIL PROTECTED]
> 
> So assuming "TheObject" is an NSMutableData object holding (at least...)

> the data block shown above, the following code hands me back "This Is 
> The Part I Want" in Result - exactly as I want it to:
> 
> NSString *Result;
> NSString *MS1 = @[EMAIL PROTECTED]
"Magic String 1 ";
> NSString *MS2 = @[EMAIL PROTECTED]
" Blow It Out Your Ear"
> 
> Result = [TheObject getStringDelimitedBy:MS1 endingWith:MS2];
> 
> Like I said, it WORKS fine. But my personal sense of style says it 
> *LOOKS LIKE* complete crap.
> 
> How would *YOU* name such a method?

- (NSString*)substringBetween:(NSString*)inStartDelimiter 
and:(NSString*)inEndDelimiter
{
}

That's just off the top of my head. It's got room for improvement, but 
I'm fairly certain I'd start with 'substring'. Objective-C methods that 
start with 'get' are rare and from a quick survey appear to have the 
behavior of filling a provided buffer.

For what it's worth, I'd make it a category on NSData. There's nothing 
about such a method that should require mutability.

G

-- 
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
   - Harry Potter and the Odor of the Phoenix
 




 3 Posts in Topic:
Trivial/stupid naming convention/cosmetics query - What would YO
Don Bruder <dakidd@[EM  2008-06-22 14:26:02 
Re: Trivial/stupid naming convention/cosmetics query - What woul
Gregory Weston <uce@[E  2008-06-22 17:40:31 
Re: Trivial/stupid naming convention/cosmetics query - What woul
Don Bruder <dakidd@[EM  2008-06-22 16:11:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:27:17 CST 2008.