ADT’s have spoiled me
Rust has many benefits over other languages, such as not requiring a GC, opt-in unsafety, ownership semantics, powerful macros, etc.
Most of that is really cool, but I’m not a systems programmer. I can get along just fine with a GC for the stuff I do.
I’m having trouble, however, using other languages and designing APIs without ADT, specifically sum types.
Languages like Typescript are fine due to discriminated unions, but Java and C#, which I used to program in a lot and enjoy, have both become difficult to write. Honestly, I don’t even know what I did beforehand.
I must have done something because I used to produce programs, but the APIs I produced must have been confusing or riddled with bugs.
I still find myself trying to hack together sum types using inheritance or marker interfaces. Marker interfaces work, but it’s very confusing to see an empty interface and it feels kind of dirty.
Is anybody else in this boat? What hacks do you use to simulate, or sidestep, sum types in languages that aren’t Rust?