4 ms·
I know you can use the empty interface but it hands off type checking to the runtime, which neglects the type system for a bit of generality and defeats the saf
by nickpresta 14y ago
I know you can use the empty interface but it hands off type checking to the runtime, which neglects the type system for a bit of generality and defeats the safety of having static typing in the first place.
- georgemcbay 14y agoYou can also import the unsafe package and mess with pointers directly. Neither of these are problems. Go strikes a nearly perfect balance between saving the programmer from accidentally shooting his foot off and getting the hell out of the way when the programmer is absolutely sure that the proper solution involves bending the rules a bit.
- nickpresta 14y agoI never said these things were problems. I only brought them up because the article doesn't even mention them, or type safety at all. It is one thing to have code for an example or for an introductory paragraph, but it should be mentioned that `interface{}` is not totally "safe" .
- batista 14y agoI don't think so. A proper solution for generics would be a "nearly perfect balance" in this case, not reflection or casting.