• 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 20:54:45 -0800

Really its just a suggestion to switch the parameters in the condition, if you find it useful.

There's really no one standard way of coding things, everyone just uses what feels natural for them.

It would however, be nice if Project Builder warned me when I had (somecondition = nil) in that while condition, instead of just ignoring it only for me to have some runtime bugs or undesired result. Or even have an option of turning this type of warning on or off depending on picky developer preference ;)

I was also reminded of that trick to #define equals ==, and maybe i'll try that ;)

Oh and I would think that it would be hard to eyeball the use of = instead of == if you are looking at lots and lots of code with conditionals, but who knows :)

And just for kicks, I usually calculate the change I'm going to get in my mind and keep that figure then count the change I receive and compare to that so arguably, I would be thinking

if (31==changereceived)
{
[Esteban pocketChange:changereceived];
[Esteban leaveStore];
}
else
[Esteban say:@"Excuse me, this is the wrong change."];

But that's just me, I also thought it cool that I crashed a computer when i first learned to program in Pascal.. If you must know it was a Quadra using OS 7.5.1, and I was learning how to make a dynamic array, i think :)

There's a surge you get when you find out just how powerful a program you write can be :)

-Esteban

On Thursday, December 20, 2001, at 12:52 PM, Steve Bird wrote:

On Thursday, December 20, 2001, at 02:59 , Esteban wrote:

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

--- Coming into C from years of Pascal (where ':=' means assignment), I was frustrated by the language's different use of a common (in every other language) comparison syntax ( If errCode = 0 ), and the compiler's acceptance of it (at least CodeWarrior could be set to warn you).
I read the suggestions of others (one company I knew even has it as a rule) to use the constant first, i.e., If (0 == errCode) .
I hated the way it reads.
I still hate the way it reads.
It's not the way I think.
Chances are it's not the way you think, either.
If you buy something for 69 cents, and the clerk gives you 31 cents change, do you think "is 31 cents the change I got?". I don't. I think "is the change I got 31 cents?"
I came to the conclusion that anyone (me included) who couldn't remember to use double equals, wouldn't remember to put the constant first, either.
It was a struggle to remember to put the constant first. It was a lesser struggle to check the double-equals than to re-arrange the arguments to the comparison operator.
And now it's second nature.


-------------------------------------------------------------------------------------
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
www.Culverson.com (toll free) 1-877-676-8175
_______________________________________________
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: Andreas Monitzer <email@hidden>
References: 
 >Re: CriticalAlert (From: Steve Bird <email@hidden>)

  • Prev by Date: Re: Contextual menus in a NSTableView
  • Next by Date: Re: Re(2): CriticalAlert
  • Previous by thread: Re: CriticalAlert
  • Next by thread: Re: CriticalAlert
  • Index(es):
    • Date
    • Thread