• 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: !foo vs foo == nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: !foo vs foo == nil


  • Subject: Re: !foo vs foo == nil
  • From: Jim Correia <email@hidden>
  • Date: Thu, 21 Aug 2008 15:42:35 -0400

On Aug 21, 2008, at 3:54 AM, Jules Colding wrote:

For that simple reason, I'd go for nil == foo every time.

Yes, and in general you should always do "if (CONSTANT == foo)" to catch the potential "if (CONSTANT = foo)" error.

If your name is Yoda, then perhaps if (3 != x) reads naturally to you. :-)


As in most things, I think it is critical to strike a balance between code readability/skim-ability and other considerations.

The previously mentioned warning will catch an unintentional assignment as long as you don't overzealously use extra sets of parenthesis.

And to use Uli's example, the compiler will happily accept

	x =+ 5;

even when that isn't what you intended. At the end of the day, you are responsible for what you typed, typos included.

Jim
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: !foo vs foo == nil
      • From: Andy Lee <email@hidden>
References: 
 >!foo vs foo == nil (From: Torsten Curdt <email@hidden>)
 >Re: !foo vs foo == nil (From: Filip van der Meeren <email@hidden>)
 >Re: !foo vs foo == nil (From: Torsten Curdt <email@hidden>)
 >Re: !foo vs foo == nil (From: "John C. Randolph" <email@hidden>)
 >Re: !foo vs foo == nil (From: Jules Colding <email@hidden>)
 >Re: !foo vs foo == nil (From: Thomas Davie <email@hidden>)
 >Re: !foo vs foo == nil (From: Jules Colding <email@hidden>)

  • Prev by Date: Re: !foo vs foo == nil
  • Next by Date: Re: !foo vs foo == nil
  • Previous by thread: Re: !foo vs foo == nil
  • Next by thread: Re: !foo vs foo == nil
  • Index(es):
    • Date
    • Thread