3 ms·
> Can someone explain the rationale for writing comparisons in the ordering they're using (e.g., 2180 < week)? https://en.wikipedia.org/wiki/Yoda_conditions ht
by inetknght 5y ago
> Can someone explain the rationale for writing comparisons in the ordering they're using (e.g., 2180 < week)?
https://en.wikipedia.org/wiki/Yoda_conditions https://en.wikipedia.org/wiki/Yoda_conditions
> it seemed error-prone to not write them the way they'd be spoken aloud
It is written the way it'd be spoken aloud. If you're not speaking it that way then you need to change the way you think. Programming is another language after all.
- colejohnson66 5y agoI don't know about you, but "week is greater than 2180" sounds more natural than "2180 is less than week"
- inetknght 5y ago> I don't know about you, but "week is greater than 2180" sounds more natural than "2180 is less than week" To you perhaps. To me, I think "if I put both sides on the number line, which way is being questioned? and is that question answered true or false?" And therefore I almost always do an equals or less-than comparison because that's how I think about the number line: 0 in the center with negatives on the left and positives on the right. So `if (week < 2048)` is just as valid and easy to think about as `if (!(2048 <= week))`. But then `if (!(2048 <= week))` provides an additional guarantee: that I won't accidentally assign to `week`.
- deleted 5y ago[deleted]