Efficiency? is there any difference between these codes?

Possible duplicate:
Is there any difference between i == 0 and 0 == i?

What are the advantages of the following coding styles, is there any difference between them?

int i; // more code if (i == 0) {...} 

against

 if (0 == i) {...} 

thanks

+1
java
source share
3 answers

It makes no difference, choose one and stick to it for consistency. (value == variable) is a relic from older languages ​​where you can randomly assign a value to a variable in if if (a = 0) instead of (a == 0)

They both turn (efficiently) into the same command instruction, so there will be no difference in performance

+2
source share

No difference.

I always found the last example less readable, and I rarely see it, but some people like it.

+3
source share

There is no difference in performance, but this style is preferred for readability:

 if (i == 0) {...} 

Another version of if (0 == i) {...} is an example of the iodine condition, and this is considered bad programming practice. Quote from the link:

"Yoda conditions" - using if (constant == variable) instead of if (variable == constant), for example if (4 == foo). Because it says, "if blue is the sky" or "if a tall man."

enter image description here

+2
source share

All Articles