Re:Too Much Go Misdirection
by stouset on Monday May 19, 2025 @04:40PM
(#44034601)
It's frightening how quickly the answer in golang becomes "downcast to interface{} and force type problems to happen at runtime".
[ Parent
| on HN ]
Re:Too Much Go Misdirection
by throwaway894345 on Monday May 19, 2025 @05:30PM
(#44035100)
You 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).