TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rust Patterns: Enums Instead of Booleans

29 pointsby lwhsiaoabout 6 years ago

3 comments

almostdeadguyabout 6 years ago
This comes up quite a bit in functional languages in the ML family (which all have ADTs like rust). Bob Harper&#x27;s blog had a post about this called &quot;boolean blindness&quot; (which seems to be locked now?), but you can find a summary of it here: <a href="https:&#x2F;&#x2F;shreevatsa.wordpress.com&#x2F;2015&#x2F;01&#x2F;31&#x2F;boolean-blindness&#x2F;" rel="nofollow">https:&#x2F;&#x2F;shreevatsa.wordpress.com&#x2F;2015&#x2F;01&#x2F;31&#x2F;boolean-blindnes...</a>
olliejabout 6 years ago
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.<p>I feel the biggest problem with Enums in c&#x2F;c++ is the default implicit bool and int conversions. They are the enemy.
butterisgoodabout 6 years ago
Hate to tell you C and C++ switch offers the same compile time safety as Rust here.<p>Just don’t add a “default” clause.
评论 #19871749 未加载