3 ms·
I at first had the opposite reaction, which is that I spend a ton of time fighting inverted ifs! But my reaction is not incompatible with yours. It's not, but i
by blandflakes 3y ago
I at first had the opposite reaction, which is that I spend a ton of time fighting inverted ifs! But my reaction is not incompatible with yours. It's not, but it is related: I HATE reading:
if (!someCondition) {
// short amount of code
} else {
// longer happy path
}
The contextual overhead of having to invert a negative (i.e. !!someCondition) is just annoying.
I do agree that if (happy) { /* tons of code / } else { / I forgot how we got here */ } can also be an issue.
- Izkata 3y agoThe key to the idea above is that you don't have any "else" clause. It's an early return, raise an exception, or modify the data so it's no longer bad.
- blandflakes 3y agoYes, that's why I said I realized they weren't quite the same situation, while adding another example of a situation where people create hard to follow structures.