No performance differenced you'd ever need to worry about.
You do see people write == tests "backwards" for a good reason. You could easily mistype "a = 10" instead of "a == 10". It's likely to be valid syntax so the compiler won't catch it, but you sure won't get the results you want. If you turn around "10 = a" the compiler will complain and help catch your tiny typo.
And when you get to objects, the "backwards" syntax helps avoid null pointer exceptions. Consider these two lines
If input is null, the first line throws an exception, but the second doesn't. For some reason it bugs me to see this:
Oh, one reason is it's easy to again mistype & instead of && and still get the darned exception! [ October 27, 2005: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James: You do see people write == tests "backwards" for a good reason. You could easily mistype "a = 10" instead of "a == 10". It's likely to be valid syntax so the compiler won't catch it, but you sure won't get the results you want.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jan 29, 2003
Yeah, I guess it would only work on booleans?
if ( x = true )
which would be silly in the first place. Still, it seems like I got burned on this at some point ... the syntax for = and == both worked. Can't remember what I was doing tho.
I almost added to that post that the "backwards" syntax very often tells you the author wrote C before Java. I didn't but I still write this way some times.
Joined: Jul 11, 2001
Originally posted by Stan James: Yeah, I guess it would only work on booleans?
if ( x = true )
which would be silly in the first place.
I'm not sure, but I seem to remember that some compilers (Eclipse?) can flag a warning for such code.