Possible Duplicate:
Is there a difference between i==0 and 0==i?
What's the benefit of the following coding styles , is there any difference between them ?
int i;
// more code
if (i == 0) {...}
vs
if (0 == i) {...}
Thanks
Possible Duplicate:
Is there a difference between i==0 and 0==i?
What's the benefit of the following coding styles , is there any difference between them ?
int i;
// more code
if (i == 0) {...}
vs
if (0 == i) {...}
Thanks
No difference at all.
I've always found the latter example less readable, and I rarely see it, but some folks seem to like it.
No difference, pick one and stick with it for consistency. The (value == variable)
is a relic from older languages where you could accidentally assign a value to a variable in an if (a = 0)
, instead of (a == 0)
They will both turn into (effectively) the same machine instruction, so there won't be any performance difference at all
There's no difference in efficiency, but this style is preferred for readability:
if (i == 0) {...}
The other version, if (0 == i) {...}
is an example of a Yoda condition, and it's considered a bad programming practice. Quoting from the link:
"Yoda Conditions"— using if (constant == variable) instead of if (variable == constant), like if (4 == foo). Because it's like saying "if blue is the sky" or "if tall is the man".