• 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: assignment in if clause
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assignment in if clause


  • Subject: Re: assignment in if clause
  • From: Kevin Grant <email@hidden>
  • Date: Mon, 26 May 2008 22:37:47 -0500

I agree that it is perfectly clear. But there is still a serious problem
with it: it is too easy to make the typo of if(a=b) when one intended
if(a==b). This can be a surprisingly difficult typo to spot, when one is
staring at the code with the preconceived belief that one typed if(a==b).

The style I adopted is to place the "most constant" part of an expression first: for example, "if (0 == x)" instead of "if (x == 0)". This generates a compile-time error for accidental assignments.

Kevin G.
_______________________________________________

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: assignment in if clause
      • From: Steve Christensen <email@hidden>
    • Re: assignment in if clause
      • From: Scott Ribe <email@hidden>
References: 
 >Re: assignment in if clause (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: File's Owner
  • Next by Date: Re: running an external app
  • Previous by thread: Re: assignment in if clause
  • Next by thread: Re: assignment in if clause
  • Index(es):
    • Date
    • Thread