4 ms·
Sum types. In C they can be constructed out of unions and structs with lots of checks (and possibility for error) but it's painful. There's really no excuse f
by retrac 3y ago
Sum types. In C they can be constructed out of unions and structs with lots of checks (and possibility for error) but it's painful.
There's really no excuse for C not having them, other than C being designed before algebraic types became mainstream. They make certain programming errors impossible, particularly with null values and misusing a union with the wrong type. It is possible to compile them as a zero-cost abstraction, and essentially all recent languages aimed at the same domain as C (Rust, D, Go, Zig, Hare, etc.) include them.
- anacrolix 3y agoGo goes NOT have sum types. I'm not sure Zig technically does, but is close enough.