Hacker News new | ask | show | jobs
by stouset 398 days ago
It's frightening how quickly the answer in golang becomes "downcast to interface{} and force type problems to happen at runtime".
2 comments

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).

Presumably the questions that have simple and easy answers don't get long comment chains.