3 ms·
It's frightening how quickly the answer in golang becomes "downcast to interface{} and force type problems to happen at runtime".
by stouset 1y ago
It's frightening how quickly the answer in golang becomes "downcast to interface{} and force type problems to happen at runtime".
- throwaway894345 1y agoYou don’t need to downcast to interface, io.Reader is already an interface, and a type assertion on an interface (“if this io.Reader is just a byteslice and cursor, then use the byteslice”) is strictly safer than an untagged union and equally safe with a tagged union. I wish Go had Rust-like enums as well, but they don’t make anything safer in this case (except for the nil interface concern which isn’t the point you’re raising).
- wredcoll 1y agoPresumably the questions that have simple and easy answers don't get long comment chains.