• 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: argument checks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: argument checks


  • Subject: Re: argument checks
  • From: Alastair Houghton <email@hidden>
  • Date: Mon, 16 Jun 2008 13:22:12 +0100

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 (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: 
 >argument checks (From: Ashley Perrien <email@hidden>)
 >Re: argument checks (From: Graham Cox <email@hidden>)
 >Re: argument checks (From: Chris Suter <email@hidden>)
 >Re: argument checks (From: Graham Cox <email@hidden>)
 >Re: argument checks (From: Chris Suter <email@hidden>)
 >Re: argument checks (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Requesting Administrator Name and Password
  • Next by Date: Re: argument checks
  • Previous by thread: Re: argument checks
  • Next by thread: Re: argument checks
  • Index(es):
    • Date
    • Thread