On 12 Jun 2008, at 13:01, Graham Cox wrote:

On 12 Jun 2008, at 5:47 pm, Chris Suter wrote:

Can you give me a counter-example?

Let’s say the function your calling uses one of the following:

-[NSDictionary setObject:forKey:]
-[NSMutableArray addObject:]

Raising an exception is a good response when a nil argument isn't appropriate, but that only shows those methods are correctly dealing with that anticipated situation. Plenty of other code uses nil to mean "use the default", or is harmless.

Sort of, yes. I think Chris's point was that you can't assume that you can pass nil arguments to any method and expect that they will just cause some sort of no-op. In the cases he lists that's clearly not what happens.

+[NSDictionary dictionaryWithObjectsAndKeys:Object1, Key1, ObjectThatIsNil, Key2, Object3, Key3, nil]

Actually that effect can be extremely handy. For example the userInfo dict to a notification can often be set up in order such that optional info can be nil - that terminates the list early and perfectly safely

I'm not sure it's a great idea to rely on this, since I think it falls into the realm of Behaviour That Is Not Obvious. But I can see it might be useful in some circumstances. Again, however, passing nil didn't have a no-op result; it did something quite different and which (if ObjectThatIsNil is a parameter to some other method) might be highly counter-intuitive.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to