In my compiler project, I have an enumeration that goes like
enum Result {
No,
Maybe,
Yes
};
I have put No
explicitly at the first position, so that i can rely on the boolean evaluation to false
. If my compiler is not sure about something, and has to wait for facts until runtime, its analysis functions will return Maybe
. Used like
if(!typesEqual(t1, t2)) {
diagnose(types_unequal) << t1 << t2;
}
I wonder whether you or your company considers it bad style not to compare to No
explicitly
if(typesEqual(t1, t2) == No) { /* ... */ }
Comparing explicitly seems wordy to me, but relying on the implicit boolean conversion somehow makes me feel guilty. Have you had that feeling before, and how have you dealt with it?