News for hackers. Stuff that matters.

richardsondrew

Re:Why I Don't Like Golang (2016) on Tuesday June 14, 2022 @01:06AM (#31734941)
> However, the issue this brings up about structs / types not explicitly declaring which interfaces they implement is a real and unaddressed problem

You can do this with a line of code below the struct definition, something like:

  var _ <interface> = &<struct>{}
The compiler will also generate helpful errors if the struct doesn't implement the interface.

Not requiring struct definition is a great feature in golang. I'm able to add an interface to a struct defined in another library to inject a different implementation for unit tests.