
Rust Patterns: Enums Instead of Booleans - lwhsiao
http://blakesmith.me/2019/05/07/rust-patterns-enums-instead-of-booleans.html
======
almostdeadguy
This comes up quite a bit in functional languages in the ML family (which all
have ADTs like rust). Bob Harper's blog had a post about this called "boolean
blindness" (which seems to be locked now?), but you can find a summary of it
here: [https://shreevatsa.wordpress.com/2015/01/31/boolean-
blindnes...](https://shreevatsa.wordpress.com/2015/01/31/boolean-blindness/)

------
olliej
This is increasingly the standard model in large C and C++ projects, alongside
the warning flags for incomplete switches and fall through you get fairly
close to this.

I feel the biggest problem with Enums in c/c++ is the default implicit bool
and int conversions. They are the enemy.

------
butterisgood
Hate to tell you C and C++ switch offers the same compile time safety as Rust
here.

Just don’t add a “default” clause.

~~~
almostdeadguy
Switch in C/C++ doesn't enforce mutual exclusivity though. You can forget a
"break" statement and fall through multiple cases.

~~~
olliej
I believe there are warning flags you can turn on for this, and compiler
defines/tokens to allow fall through.

