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 3 of 3 Topic 3780 of 3882
Post > Topic >>

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

by Don Bruder <dakidd@[EMAIL PROTECTED] > Jun 22, 2008 at 04:11 PM

In article <uce-9F1CCB.17403122062008@[EMAIL PROTECTED]
>,
 Gregory Weston <uce@[EMAIL PROTECTED]
> wrote:

> 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.

OK, I think I can go with both the naming, and the logic behind choosing 
it. Thanks.

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

Nothing whatsoever, beyond the fact that my data supply needs to be an 
NSMutableData, rather than an NSData. (since I have to load it, then do 
some pre-massaging on it before I can actually start parsing it) Which 
made NSMutableData the most obvious place to graft on my category. 

Now that you mention it and get me thinking a bit more "sideways", an 
NSMutableData is, after all, just an NSData with categories that provide 
mutation capability, so putting my category on NSData should be just as 
functional, and as a bonus, opens the method up for use on "not mutable" 
data if I ever have need for it.

Isn't "Don't re-write, re-use" one of the big OOP mantras? :)

-- 
Don Bruder - dakidd@[EMAIL PROTECTED]
 - If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info
 




 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 10:33:25 CST 2008.