3 ms·
For the range case, languages like Python got it right because the statement "1 < x < 5" means exactly what it would seem to mean. For other languages I’m not
by makecheck 11y ago
For the range case, languages like Python got it right because the statement "1 < x < 5" means exactly what it would seem to mean.
For other languages I’m not sure it matters for inequalities.
For equality though, I always use the form "if (constant == x)" as opposed to "if (x == constant)" because in C it guarantees that the compiler will trip over an accidental-assignment typo. That is, "if (constant = x)" is a compilation error but "if (x = constant)" might be missed.
- dsego 11y agoAlso known as Yoda conditions. https://en.wikipedia.org/wiki/Yoda_conditions https://en.wikipedia.org/wiki/Yoda_conditions