I was intrigued by what Scott Ambler says in his Java Coding Standards book , and I quote:
2.5.2 Place the constants on the left side of the comparisons
Therefore, he recommends using
if ( 1 == something ) {…}
if ( 0 = x ) { …}
instead
if ( something == 1 ) {…}
if ( x = 0 ) { …}
OMG !!!
And he motivates this by saying that:
"Although they are both equivalent, at least at the first inspection, the code on the left compiles , and the code on the right does not."
As I know (when I started programming Java, Java 14. was already used), both conditions will throw a compiler error.
Starting with the Ambler instruction, I tried to search when the Java syntax if ( x = 0 );was ever compiled.
? JSR, , , Java.
Jre7 target source 1.2 . , Java 1.1: 9
:
if(x = 0); Java?