Go Interfaces Debate
The cluster focuses on debates about Go's interfaces, including their structural and duck typing nature, comparisons to type classes in other languages, criticisms like interface pollution and overuse of interface{}, and defenses of their design.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Not proficient in Go but I see an interface{} somewhere in the answer.
Go has type classes, they're called interfaces
Is it possible to write a reusable version of something like this in Go without using interface{}?
Not really, Go uses duck typing for interfaces. You declare an interface to require functions X, Y, and Z. Any type that has functions X, Y, and Z suddenly implements that interface whether you want it to or not.
Go's interfaces are not type-classes and type-classes aren't about structural typing.
Go is not immune. See: interface pollution.
Go's interfaces are not like Haskell's typeclasses. Just try and write a Go interface that allows you to add two of the same things together.
Go’s structural interfaces are one of the worst features of the language, partially due to the implementation and partially due to the fact that structural typing like in Go is just a terrible idea in a statically typed language. May as well just use a dynamically typed language: because that’s what go’s duck typing leads a code base to be in practice anyway
Because Go doesn't support userland generic types, I see liberal use of `interface{}` types in APIs. There must be a better way.
Go is horrible due to the absence of specific "interface implementation" markers. Gets pretty hard to find where or how a type implements an interface.