2 ms·
Unless has negation built in. Which is why unless is such a hard concept for people to grasp, not just in code, but also in regular English. At least the "if
by asdajksah2123 4y ago
Unless has negation built in.
Which is why unless is such a hard concept for people to grasp, not just in code, but also in regular English.
At least the "if not" makes the negation explicit, which can then be easily eliminated using several different techniques (early return, swap with the else condition) if the negation is confusing enough.
However, "unless" necessarily includes negation because that's how the word is defined.
- mattarm 4y ago> Which is why unless is such a hard concept for people to grasp, not just in code, but also in regular English. This is the first I've heard about this confusion over the word "unless" in English. In spoken English I do notice that most often the "unless" comes after a statement. Example: "I'll be there on time, unless the bus is late." That is more clear (to me) than "I'll be there on time, if the bus is not late." Maybe not by coincidence, I tend to like "unless" when it follows the action in in Ruby code, too.