• 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: [OT][PB] if ( x = y ) mistake warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT][PB] if ( x = y ) mistake warning


  • Subject: Re: [OT][PB] if ( x = y ) mistake warning
  • From: Sailor Quasar <email@hidden>
  • Date: Sun, 6 Jul 2003 15:10:39 -0400

On Sunday, July 6, 2003, at 02:43 PM, Bill Cheeseman wrote:
How can I turn on a warning for the mistake if ( x = y ) in Project
Builder?
How would Project Builder know it is a mistake? It's perfectly valid C code.
It assigns y to x, then tests the result for nil or non-nil. This locution
is used frequently in Cocoa init methods, where one generally writes:

if (self = [super init]) { ...

with a single equals sign. If the result is nil, it is documented to mean
that the superclass failed to initialize itself.

I always write "if ((self = [super init])) {".

In my personal opinion, it wouldn't be right to have the compiler generate a
warning for this. In general, I wouldn't want my compiler to become so
strict that it reminded me of good coding practices as opposed to
non-obvious potential errors. I suppose the dividing line is a matter of
judgment or personal taste, but this one I wouldn't want.

I respectfully disagree. In my experience, using a single equals sign in an if is Far more often an error than not, and in those cases which aren't the compiler can be very easily silenced with an extra pair of parenthesis. It is certainly valid C code, but outside the Cocoa -init methods I do not generally see a large-scale use of it. I believe that if others did not agree, the compiler warning would not exist at all to be turned on. (Disclaimer: all IMHO :).

-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden
_______________________________________________
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: [OT][PB] ( x = y ) warning - switch behavior
      • From: Jim Witte <email@hidden>
  • Prev by Date: Project Builder and scripting
  • Next by Date: Re: Speed up drawing of View with multiple NSBezierPaths
  • Previous by thread: Re: Cocoa Command Line Application
  • Next by thread: Re: [OT][PB] ( x = y ) warning - switch behavior
  • Index(es):
    • Date
    • Thread