News for hackers. Stuff that matters.
Re:Everyday hassles in Go by ominous_prime on Tuesday December 30, 2014 @09:38AM (#8814713)
> Or why expose this interface {} feature and allow people to use it in a statically typed language?

`interface{}` isn't anything special, or something akin to `void*`. Interfaces are a core part of the language, and `interface{}` is just the literal form for an "interface with no methods", which happens to match anything since all types can fulfill an empty method set. It's no different than using this `Something` for exmaple:

    type Something interface {
    }
Re:Everyday hassles in Go by TheHydroImpulse on Tuesday December 30, 2014 @12:38PM (#8815635)
I'm assuming he meant why would they expose or promote the use of a construct that bypasses type safety in a statically typed language. Although `interface {}` is not some sort of special feature, it's still circumventing the type system.
Re:Everyday hassles in Go by ominous_prime on Tuesday December 30, 2014 @12:55PM (#8815714)
You don't lose "type safety", as interfaces retain all type information -- you're not casting `void*` pointers (without the unsafe package), and type conversions are limited and well defined.

It however does pass the type checking to run-time instead of compile-time, which is a trade-off that some feel is worth the language simplicity.

Re:Everyday hassles in Go by TheHydroImpulse on Tuesday December 30, 2014 @04:03PM (#8816713)
> It however does pass the type checking to run-time instead of compile-time

That's absolutely still loosing type safety. Reflections don't substitute type safety.

Re:Everyday hassles in Go by ominous_prime on Wednesday December 31, 2014 @07:26AM (#8819086)
No, it's still type safe (http://en.wikipedia.org/wiki/Type_safety), memory safe, and free of undefined behavior. There's is no way to use a type contained in an interface as the incorrect type (without the unsafe package, but that wouldn't need an interface anyway), or to inadvertently access or modify arbitrary memory.

I also wouldn't consider Go type assertions to be in the same class as reflection. A type assertion is the way you extract and check the underlying type from an interface, and is quite common even when using more complex interfaces. There's also no way to make use of the underlying type from an interface without first asserting it as that type.

Re:Everyday hassles in Go by TheHydroImpulse on Wednesday December 31, 2014 @12:39PM (#8820199)
Type assertions happen during runtime, thus using reflections. There is no other way than to use reflections.