• 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: CriticalAlert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CriticalAlert


  • Subject: Re: CriticalAlert
  • From: Esteban <email@hidden>
  • Date: Thu, 20 Dec 2001 11:59:04 -0800

A coding style technique I've learned recently (gosh, i can't believe it
took me so long and I've been coding for 3 years in C/C++) is to
include the fixed value you are checking against first in the
conditional.

In this way if you mistyped and used only one = instead of the usual ==
you will get a compiler error, because the fixed value can not be
reassigned.

For example,
you can do
if( NSAlertAlternateReturn = alertResult)
at this point because you forgot to use == instead of =, the compiler
will b*tch at you, and tell you how brilliant you are ;)
then you'll just fix that right then to the correct way
if( NSAlertAlternateReturn == alertResult)

From experience, a lot of times the error of using the single = instead
of == is pretty common, so I've forced myself to do things the other way
(check the constant value against the variable value in a condition,
instead of the variable value against the constant) thus avoiding
problems, if I accidently type = and not ==

And of course if you make the error of just doing

if(alertResult = NSAlertAlternateReturn)

You'll be pulling your hair out for a while because everything compiles
fine, and your code "looks" right, and it DOESN'T WORK!!!! $%#@! (its
happened to me quite a lot)

Hehe ;)

Anyways we all go through that error of using a = instead of a == so
don't beat up yourself, just be careful and I suggest change your
technique, so at least the brainless compiler can help you fix your code
before runtime ;)

-Esteban

On Thursday, December 20, 2001, at 08:52 AM, Diggory Laycock wrote:

You want (alertResult == NSAlertAlternateReturn), etc. That is, "==",
not "=".

Thanks - I was being stupid!
_______________________________________________
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: CriticalAlert
      • From: Steve Bird <email@hidden>
  • Prev by Date: Re(2): CriticalAlert
  • Next by Date: Re: CriticalAlert
  • Previous by thread: Re(4): CriticalAlert
  • Next by thread: Re: CriticalAlert
  • Index(es):
    • Date
    • Thread