MLUG: [MLUG] Testing results
[MLUG] Testing results
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
> > Personally I use the first style, but switch it to:
> >     if (1 == testcase) {
> > That way if you make the common mistake of using a '=' instead of an
> > '==' you'll get a compiler error.  I have no idea where I first liearned
> > this but I tend to use it in any langugae.  Putting the constant on the
> > left side of the comparison prevents accidentally assigning a value to
> > the variable.

Another very, very good reason to use the "known value" on the LEFT side
of a test is that the compiler knows the datatype of the left side, and
therefore will coerce the RIGHT side to that same type.

This is particularly important in scripting languages with variadic run-time
typing, such as Perl, PHP, Python, Groovy, etc.

But it can also come into play where the C/C++ compiler is inserting magical
type casts in your code, and then bite you in the arse. For example, char to signed
or unsigned char, char to un/signed int, char to un/signed long, etc.

Putting the known value on the left determines the "type" of the evaluation being performed.
This works for operations besides the logical operators as well.

Mike/
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members