Hacker News new | ask | show | jobs
by froh 41 days ago
can't you explicitly express a catch-all in a check?

edit: I don't know rust. in other languages he's such catch all patterns exist and you have to either capture each possible value explicitly or you express "here in this fu, I take care of these and all others I do that..."

1 comments

Yes you can, but if a new enum value appears, there's probably something you want to do in response which your default case didn't do.
The suggestion seems to be for api changes where the api is generated from an idl. So proto or something. If my service was built several versions prior to that value being added then I by definition don't care about it. The catch all is fine. If other services care that I don't care, they can file a ticket. You could be nice and leave out the catch all and then the deserialization will panic or throw and error. And the mect CI pipeline where the new IDL gets used will fail to compile. Both ways it is a runtime error at first. If you don't require exhaustive at all, that just lets you persist the situation without migrating my old service to the new api... Non exhaustive is the one option I can't agree ever makes sense.