Skip navigation.
 
mlRe: Why is [nil aMessage] a no-op?
FROM : Citizen
DATE : Fri Apr 18 15:22:30 2008

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

Related mailsAuthorDate
mlWhy is [nil aMessage] a no-op? Adam P Jenkins Apr 18, 00:42
mlRe: Why is [nil aMessage] a no-op? Nick Zitzmann Apr 18, 01:00
mlRe: Why is [nil aMessage] a no-op? Bill Bumgarner Apr 18, 01:07
mlRe: Why is [nil aMessage] a no-op? Jeff Apr 18, 02:46
mlRe: Why is [nil aMessage] a no-op? Graham Cox Apr 18, 03:19
mlRe: Why is [nil aMessage] a no-op? David Wilson Apr 18, 03:51
mlRe: Why is [nil aMessage] a no-op? Michael Ash Apr 18, 04:13
mlRe: Why is [nil aMessage] a no-op? Adam P Jenkins Apr 18, 06:20
mlRe: Why is [nil aMessage] a no-op? Bill Bumgarner Apr 18, 06:47
mlRe: Why is [nil aMessage] a no-op? Adam P Jenkins Apr 18, 06:56
mlRe: Why is [nil aMessage] a no-op? Adam P Jenkins Apr 18, 07:01
mlRe: Why is [nil aMessage] a no-op? Graham Cox Apr 18, 07:16
mlRe: Why is [nil aMessage] a no-op? Michael Vannorsdel Apr 18, 07:21
mlRe: Why is [nil aMessage] a no-op? Bill Bumgarner Apr 18, 07:46
mlRe: Why is [nil aMessage] a no-op? Sherm Pendley Apr 18, 07:52
mlRe: Why is [nil aMessage] a no-op? Jens Alfke Apr 18, 08:13
mlRe: Why is [nil aMessage] a no-op? Gerriet M. Denkman… Apr 18, 10:32
mlRe: Why is [nil aMessage] a no-op? ab_lists Apr 18, 10:56
mlRe: Why is [nil aMessage] a no-op? Citizen Apr 18, 15:22
mlRe: Why is [nil aMessage] a no-op? Adam P Jenkins Apr 18, 15:56
mlRe: Why is [nil aMessage] a no-op? Scott Ribe Apr 18, 16:49
mlRe: Why is [nil aMessage] a no-op? Andy Lee Apr 18, 17:18
mlRe: Why is [nil aMessage] a no-op? Rob Napier Apr 18, 18:19