Re: Avoiding == and = mixup in if statements
Re: Avoiding == and = mixup in if statements
- Subject: Re: Avoiding == and = mixup in if statements
- From: Ondra Cada <email@hidden>
- Date: Fri, 21 May 2004 20:33:25 +0200
Steve,
On 21.5.2004, at 20:28, Ondra Cada wrote:
>
Actually, in my *personal* opinion the best pattern for pointers
>
(which includes, of course, objects) is omitting the "nil" altogether:
>
a condition
>
>
if (myObj) whatever...
>
>
reads very intuitively "if there's myObj do whatever" (or, "if
>
(!myObj)..." reads "if there's no myObj..."). And, of course, no typo
>
is possible.
Ah, and I forgot: there's a very nice added benefit of being able to
exploit one of the GCC extensions, providing a "default-on-nil value"
using the ?: operator without the second expression, like
NSLog(@"the value is %@",myObj?:@"unknown");
(Of course, as with all those 'don't evalute twice' tricks it becomes
truly useable as soon as there's an expression instead of myObj, an
expression which may potentially have side effects.)
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.