Functionally, there is no difference.
Some developers prefer writing the second format to avoid assignment typos(in case you miss a =
), so that compiler warns of the typo.
The second is famously known as Yoda Condition.
I say there is no difference because, you cannot guard yourself against every minuscule detail and rely on compiler to cry out aloud for you.If you intend to write a ==
you should expect yourself to write a ==
and not a =
.
Using the second format just leads to some obscure non-readable code.
Also, most of the mainstream compilers warn of the assignment instead of equality typo by emitting an warning once you enable all the warnings(which you should anyways).