• 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: Prachi Gauriar <email@hidden>
  • Date: Fri, 21 May 2004 01:53:53 -0500

On May 20, 2004, at 11:57 PM, Nicko van Someren wrote:

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.

A discussion similar to this one got a bit out of hand last year, so before anyone replies to this message or the previous one, I suggest you check out this thread in the archives first:

<http://cocoa.mamasam.com/COCOADEV/2003/06/1/65121.php>

Just a suggestion. :-)

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

  • Prev by Date: Re: Avoiding == and = mixup in if statements
  • Next by Date: Re: build styles override target settings (was: does not execute on launch)
  • Previous by thread: Re: Avoiding == and = mixup in if statements
  • Next by thread: Re: Avoiding == and = mixup in if statements
  • Index(es):
    • Date
    • Thread