4 ms·
> A few years ago people were so entrenched in their object-oriented upbringing that sum types were considered "weird functional stuff" A step further: I was
by epage 4y ago
> A few years ago people were so entrenched in their object-oriented upbringing that sum types were considered "weird functional stuff"
A step further: I was hearing talk of enums being a code smell and that they should all be replaced with interfaces as they represented alternative implementations and you might want to be more extensible or insert a mock for testing
As an aside, tagged unions weren't a big deal to me (though I thought it neat to merge tagged unions with enum constants) but what blew me away was when I learned they could have methods and implement traits. Would love it if Rust took it a step further and made the variants types. There are cases were id like to have builder methods on variants. The closest I can get is having an explicit struct and implementing From to the enum. Also wish there was variant visibility so I wouldn't have to wrap my enums in structs to hide the variants.