42 ms·
I agree, but without pattern matching converting "boolean-like" enums get tedious. For example: ConnectionMode connectionMode; if (useHttpsCheckbox.sel
by msm_ 4y ago
I agree, but without pattern matching converting "boolean-like" enums get tedious. For example:
ConnectionMode connectionMode;
if (useHttpsCheckbox.selected == ListItem::Selected) {
connectionMode = ConnectionMode::Https;
} else if (useHttpsCheckbox.selected == ListItem::Unselected) {
connectionMode = ConnectionMode::Http;
} else {
shouldNeverHappen();
}
In the real world there are often even longer chains like this - I found that bool-like variables ofter mean slightly different things at different layers of abstraction.
And also, you could simplify that by ignoring the `else` entirely, but there are no guarantees that it won't break later. For example another contributor may add ConnectionMode::TryHttpsElseHttp, and compiler won't help us. Languages with pattern matching don't have this particular problem.
- gpderetta 4y agoYou can of course use a switch statement and the compiler will warn if the cases are not exhaustive for the enum.