3 ms·
One simplification that might be tempting is to replace the "if !condition" with "if condition". For example, line 463 shows: if !found { // handle miss
by apo 8y ago
One simplification that might be tempting is to replace the "if !condition" with "if condition".
For example, line 463 shows:
if !found {
// handle missing
} else {
// handle found
}
I would simplify this to:
if found {
// handle found
} else {
// handle not found
}
Or even:
if missing {
// handle missing
} else {
// handle not missing
}
The test-negative style is repeated throughout the file, but inconsistently. Sometimes the negative is tested in the if branch, sometimes it's tested in the else branch. Why?
- gtrubetskoy 8y agoMy guess is that this is in line with the Go tradition of first handling all the odd cases leaving the essential part of what the function (or block of code in this case) attempts to do as the last part. So "if !found" to me suggests that this is more of an exception than the rule and this is why the code is written so as to deal with it first.
- AgentME 8y agoMaybe they always put the standard path first, and the negative `if !found {` lines are places where `found` is usually false.