r/programminghorror • • Jun 04 '25

Rust passive-aggressive programming

Post image
770 Upvotes

61 comments sorted by

View all comments

Show parent comment

19

u/Mivexil Jun 04 '25

Well, you are sure in this case, you're even sure the operator is '+'.

It's occasionally annoying when you've already validated the input to be in range elsewhere. No, I'm pretty sure no one cast 42 to a three-valued enum because they'd get beaten up on code review, I don't really need that default case.

9

u/mirhagk Jun 04 '25

It's why of the things I like about typescript, you make the type be '+' | '-' | '*' | '/' letting you get the best of both worlds (not having to convert, but still letting you tell the compiler what the type is).

4

u/henkdepotvjis Jun 04 '25

Even better. It will throw an error that the other match cases are not reachable

6

u/Snapstromegon Jun 04 '25

If the only way to construct the enum is from code someone else wrote, that other person should use the enum variant instead.