Switching if statements around bad practice?

I remember being told that having an if statement, such as if(10 == $myVariable), is bad practice. However, why is this bad practice and what is its name? (I can vaguely remember that he has a specific name).

+4
source share
3 answers

According to a message in the blog of Jeff Atwood Horror coding , user the StackOverflow zneak calls this condition Yoda. The description is as follows:

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

Yoda, .

exussum , , .

+2

-

if (10 = $myVariable)  

,

if ($myVariable = 10)

if true, $myVariable 10

, .

http://en.wikipedia.org/wiki/Yoda_conditions

+11

, null , Java. , , myVariable null:

if ("foo".equals(myVariable)) {
    // Do something
}

NullPointerException:

if (myVariable.equals("foo")) {
    // Do something
}

, , - :

if (myVariable != null && myVariable.equals("foo")) {
    // Do something
}
+4
source

All Articles