Re: message to nil? (very basic question)
Re: message to nil? (very basic question)
- Subject: Re: message to nil? (very basic question)
- From: Christophe Dore <email@hidden>
- Date: Mon, 21 Jan 2002 12:36:57 +0100
IMHO, the only problem with messaging nil is when nil in a variable is
an unexpected value at that time.
It propagates and often amplifies an error situation.
So, I beleive that nil messaging is safe as long as you use assertions
for those case.
Java being unable to assert (until maybe 1.4, still in beta) those guys
chose to disallow it.
Bill Bumgarner wrote:
Actually, Ondra was right.
Messages to nil will *never* cause a problem.... Andrew's message--
and Vince's followup-- refer to attempting to find meaning in whatever
is returned by a message to nil.
I.e.:
NSView *foo = nil;
NSRect bounds;
float x;
[foo bounds]; // will always work
bounds = [foo bounds]; // will always work but...
x = bounds.size.width; // ... will be undefined
x = [foo bounds].size.width; // messaging will work, rest will not
--
A bit of a nit, admittedly.
b.bum
On Sunday, January 20, 2002, at 05:55 PM, cocoa-dev-
email@hidden wrote:
Read the rest of Andrew's message a bit more carefully, he is correct.
If the nil object returns a float or a structure you might not get
back 0.
0 in the case of floats or and empty stucture.
its okay for objects and ints.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.