• 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: Avoiding == and = mixup in if statements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: Avoiding == and = mixup in if statements (From: Chris <email@hidden>)
 >Re: Avoiding == and = mixup in if statements (From: Steve Bird <email@hidden>)
 >Re: Avoiding == and = mixup in if statements (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Avoiding == and = mixup in if statements
  • Next by Date: Re: Avoiding == and = mixup in if statements
  • Previous by thread: Re: Avoiding == and = mixup in if statements
  • Next by thread: Re: Avoiding == and = mixup in if statements
  • Index(es):
    • Date
    • Thread