Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Functional Programming in Go with Generics.
That is wrong.
Interface is a special type in Go. All interfaces in go, including ones you declare, hold 2 pieces of data in memory
1. Pointer to the concrete type
2. Metadata about the concrete type
interface{} is not a special thing, it is just the empty interface, and everything satisfies the empty interface.
This is quite neat. All a type assertion does is follow the pointer and check the type data.
There is also a type switch in Go. https://play.golang.org/p/22aegLocHXI
This makes building handlers around the dynamic type easy. But for the most part: Single function interfaces. Compose those to make make larger interfaces if absolutely needed (see io.Writer, io.Reader and io.ReadWriter)
There are no comments on this comment yet.
That is wrong.
Interface is a special type in Go. All interfaces in go, including ones you declare, hold 2 pieces of data in memory
1. Pointer to the concrete type
2. Metadata about the concrete type
interface{} is not a special thing, it is just the empty interface, and everything satisfies the empty interface.
This is quite neat. All a type assertion does is follow the pointer and check the type data.
There is also a type switch in Go. https://play.golang.org/p/22aegLocHXI
This makes building handlers around the dynamic type easy. But for the most part: Single function interfaces. Compose those to make make larger interfaces if absolutely needed (see io.Writer, io.Reader and io.ReadWriter)