• 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:28:23 +0200

Steve,

On 21.5.2004, at 19:32, Steve Bird wrote:

> Can you explain how I can remember to put the arguments in backwards,
> if I can't remember to use "==" instead of "="?

;)

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.

That of course does not solve cases with a more complicated
expressions, like

if (myObj==[NSNull null]) ...

for these I personally would recommend the (already mentioned by
others) -Wparentheses warning.
---
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.


  • Follow-Ups:
    • Re: Avoiding == and = mixup in if statements
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Avoiding == and = mixup in if statements (From: Chris <email@hidden>)
 >Re: Avoiding == and = mixup in if statements (From: Steve Bird <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