3 ms·
Doing nothing is the point; it serves the same purpose as a `void*` in C, except that there are (runtime-) safe ways to take a value out of `interface{}` and ba
by tptacek 5y ago
Doing nothing is the point; it serves the same purpose as a `void*` in C, except that there are (runtime-) safe ways to take a value out of `interface{}` and back to its concrete type in Go. The most obvious use for it is heterogenous containers.
- nixpulvis 5y agoRuntime safe and statically type checked are two fundamentally different things is my point. Interfaces in most typed languages are static concepts, though there are always exceptions.
- strbean 5y agoYou can think of interface{} like Object in Java. Interfaces in go are simply saying "this thing satifies these properties". interface{} is an interface that anything can satisfy.
- nixpulvis 5y agoI will continue to think of interface{} as Any in Rust.
- ibraheemdev 5y ago`interface{}` used as a type is almost exactly `Box<dyn Any>`.
- throw_m239339 5y ago> The most obvious use for it is heterogenous containers. You mean runtime generic container without the benefits of compile-time type checking, opening the developer to runtime type errors purely for ideological reasons...
- a1369209993 5y ago> opening the developer to runtime type errors purely for ideological reasons... To be fair, there are also language-implementor-laziness reasons.
- earthboundkid 5y agoThat Go would benefit from generics doesn't change the fact that there are also lots of use for heterogenous containers. As it is, Go already has "slices" for type safe containers. The fair complaint about Go is it's hard to do other type safe container than the built in "slice" and "map" containers. But the problem is on track to be fixed next year, so it's silly to complain about it now.
- earthboundkid 5y agoThat Go would benefit from generics doesn't change the fact that there are also lots of use for heterogenous containers. As it is, Go already has "slices" for type safe containers. The fair complaint about Go is it's hard to do other type safe container than the built in "slice" and "map" containers. But the problem is on track to be fixed next year, so it's silly to complain about it now. It's really hard to take people who complain about Go seriously when they're pretty obviously just zealots who don't know much about the language besides "types good" and "Go bad". My stance: types good in moderation; Go a useful tradeoff of engineering attributes.
- throw_m239339 5y ago> so it's silly to complain about it now. No it isn't, Go has other flaws stemming from the exact same root cause and it has nothing to do with programming...
- tptacek 5y agoI think you read my comment as an invitation to debate dynamic vs. static safety checking. That seems like a deeply uninteresting debate. I'm just saying, there's a clear purpose to `interface{}`, and the same pattern shows up (though obviously much less frequently) in Rust.