• 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: Nicko van Someren <email@hidden>
  • Date: Fri, 21 May 2004 05:57:40 +0100

On 21 May 2004, at 4:47, Chris Pavicich wrote:

Why not write:

if ( nil == myObject)
{ doSomething(); }

If you miss the extra '=' the compiler will complain.

An argument against solving the problem this way is that now the code here is not naturally representing what the programmer is thinking. Most people are thinking "is my object pointer nil?", not "is nil equal to the value of my object pointer". In my experience allowing code to better represent what you are thinking is very good for both avoiding bugs and allowing you to understand the code when you revisit it later.

Nicko
_______________________________________________
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: Prachi Gauriar <email@hidden>
References: 
 >Avoiding == and = mixup in if statements (From: Christoffer Lerno <email@hidden>)
 >Re: Avoiding == and = mixup in if statements (From: Chris Pavicich <email@hidden>)

  • Prev by Date: Re: Capabilities of Quartz: rotation? zooming?
  • 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