3 ms·
Maybe I'm missing something, but you can do this with a type switch: http://play.golang.org/p/jF_bPQdwxk http://play.golang.org/p/jF_bPQdwxk It just depends on
by beatgammit 13y ago
Maybe I'm missing something, but you can do this with a type switch: http://play.golang.org/p/jF_bPQdwxk http://play.golang.org/p/jF_bPQdwxk
It just depends on what you're trying to accomplish, but most use-cases can be accomplished without exceptions. The other use-cases often indicate bad design.
As for generics, you can get 90% of the way there with interfaces. The use of `interface{}`--while sometimes necessary--is often an indicator of bad design.
In large code bases, you often don't need (or care) to know what underlying type something is. For example, you shouldn't care whether an `io.Reader` is a TCP socket, file or completely in-memory ala `io.Pipe()`.
There are times when type assertions are the best/only way to get something done, and that's why they're there, but those cases should be relatively infrequent.
Generics would make some things easier (Rust's implementation is quite nice), but it's not significantly impacting my productivity, and I certainly wouldn't consider switching languages just because Go lacks them.
EDIT: Added info about generics