• 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: C question for you old guys ;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C question for you old guys ;-)


  • Subject: Re: C question for you old guys ;-)
  • From: Jay Prince <email@hidden>
  • Date: Thu, 12 Jun 2003 17:45:00 -0700

On Wednesday, June 11, 2003, at 03:47 PM, Steve Bird wrote:
Maybe I missed it, but why do people not just put the constant on the left-hand side of the comparison?

if (1 = foo) won't compile. Typing = instead of == is a bug I've only committed once, that I can recall... but I started putting the constant on the left just in case anyway.


Maybe you can explain to me why, if you can remember to reverse the "natural" order of things when you're typing, you can't just remember to type the second "=" to begin with?

I can. As I mentioned, typing = instead of == is a bug I think I've only done once.

As to it being natural to put them the other way, I'm not so sure. At first it looks funny to say if (1 == foo) but after awhile it starts to look more appropriate to me. And I don't find it hard to read-- its more obvious that its not an assignment!

I have known programmers who said if (foo = 1) intentionally... but I think that's a bad idea.

If I can't remember to put the second "=" in, why would I remember to reverse the operand order?

The two are equivalent. One isn't "Reverse" of "normal".

If you put the constant first, you don't risk the error, that's all.

This idea was suggested to me at a job once and I adopted it, even though I don't forget to type ==, it works for me. And it seems a lot clearer and cleaner and easier to read, than defining "is" to be "==".

Jay
_______________________________________________
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: 
 >Re: C question for you old guys ;-) (From: Steve Bird <email@hidden>)

  • Prev by Date: [OT] Re: Separate list really needed?
  • Next by Date: Re: WWDC tools wishlist (was Re: troubling article)
  • Previous by thread: Re: C question for you old guys ;-)
  • Next by thread: Re: C question for you old guys ;-)
  • Index(es):
    • Date
    • Thread