• 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: Why is [nil aMessage] a no-op?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is [nil aMessage] a no-op?


  • Subject: Re: Why is [nil aMessage] a no-op?
  • From: Citizen <email@hidden>
  • Date: Fri, 18 Apr 2008 14:22:30 +0100


On 18 Apr 2008, at 05:56, Adam P Jenkins wrote:


On Apr 18, 2008, at 12:47 AM, Bill Bumgarner wrote:

On Apr 17, 2008, at 11:20 PM, Adam P Jenkins wrote:
Exactly. And now that the convention of methods returning self no longer exists, it seems like there's no longer any advantage to this behavior.

There are 10s of thousands invocations of methods on nil objects during the normal, non-error-path, execution of your average Cocoa application that indicate that this behavior is still, very much, used to the advantage (where 'advantage == convenience') of Cocoa programmers.


Can you give an example of where invoking methods on nil objects would make sense in a non-error-path situation? I'm not trying to be argumentative here, I'm really curious to know what Objective-C idioms take advantage of the nil-swallows-messages behavior. Thank you.

Do these count?

1.
// add user defined savepath to savepath menu
NSString * userpath = [[NSUserDefaults standardUserDefaults] objectForKey:ZNCDRevPrefUserDefinedSavepathKey];
if (userpath) {
[savepathPopUpButton insertItemWithTitle:[[NSFileManager defaultManager] displayNameAtPath:userpath] atIndex:2];
NSMenuItem * userDefinedMenuItem = [savepathPopUpButton itemAtIndex:2];
[userDefinedMenuItem setTag:CDRevPrefUserDefinedSaveMethod];
}


2.
- (BOOL) isPreEmphasisEnabledForSession:(int)aSession track:(int)aTrack;
{
return [[[[[[[self TOCPlist] objectForKey:ZNDiscTOCSessionsKey] objectAtIndex:(aSession-1)] objectForKey:ZNDiscTOCSessionTrackArrayKey] objectAtIndex:(aTrack-1)] objectForKey:ZNDiscTOCTrackPreEmphasisEnabledFlagKey] boolValue];
}


If not nil messaging certainly makes life easier in these situations.

- Dave
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Why is [nil aMessage] a no-op? (From: Adam P Jenkins <email@hidden>)
 >Re: Why is [nil aMessage] a no-op? (From: Bill Bumgarner <email@hidden>)
 >Re: Why is [nil aMessage] a no-op? (From: Adam P Jenkins <email@hidden>)
 >Re: Why is [nil aMessage] a no-op? (From: Bill Bumgarner <email@hidden>)
 >Re: Why is [nil aMessage] a no-op? (From: Adam P Jenkins <email@hidden>)

  • Prev by Date: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • Next by Date: Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
  • Previous by thread: Re: Why is [nil aMessage] a no-op?
  • Next by thread: Re: Why is [nil aMessage] a no-op?
  • Index(es):
    • Date
    • Thread