Can anyone explain what is the benefit of comparing constant and variable with constant on the left e.g.
if (0 == variable)
Instead of
if (variable == 0)
Can anyone explain what is the benefit of comparing constant and variable with constant on the left e.g.
if (0 == variable)
Instead of
if (variable == 0)
If you say
if (variable == 0)
you are under the risk of omiting one =
and saying
if (variable = 0)
which will set the variable variable
to 0
.
So putting 0
to the left makes it more typo-safe, because 0 = variable
won't be able to set any value to the variable.