Possible Duplicate:
Conditional Statements difference
I wanted to know what is a good way of writing the code :
X != null
or
null != X
Both of them will do same thing, but sometimes I see people write null != X so I am not sure what is a good way of writing it.
The convention of reversing comparisons as
null != Xcomes mainly from C whereis easily confused with
which is a valid statement that overwrites X with NULL instead of checking if it’s NULL.
Turning the comparison the other way;
works just as well, but confusing the equals operator with assignment
will actually give a compilation error.