On 30/11/2010, at 9:09 PM, Michael Watson wrote:

> this is not correct; there are more possibilities than 0 being returned. in 
> most situations, sending a message to nil does indeed yield a return value of 
> 0/nil. but that's not true all of the time:


But it is true probably more than 99% of the time (where I also mean 0 to mean 
nil object ref or a nulled data structure in accordance with the reference you 
cited).

For the level of the questioner, it's a close enough approximation and there is 
no value in being so pedantic where it would confuse and worry more than it 
would enlighten. Lots of people new to Cocoa bring with them defensive coding 
from other languages such as C++ (like checking for nil before sending any 
message) and the point is that in most cases it's just not necessary.

Returning nil from a class factory method if some condition is not met is 
therefore perfectly legitimate, even if the caller wasn't particularly 
expecting it - and that was what the OP was asking.

--Graham


_______________________________________________

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 arch...@mail-archive.com

Reply via email to