3 ms·
I suspect you've only seen poorly written Go, which is actually quite pervasive. The most common sign of it is the overuse of interfaces. You basically shouldn'
by roncesvalles 2y ago
I suspect you've only seen poorly written Go, which is actually quite pervasive. The most common sign of it is the overuse of interfaces. You basically shouldn't define your own interface unless you need to export functionality. Interfaces are not a tool for organizing your code. Go is meant to be written in a very linear and naïve way, and it turns out quite good when you just do that.
- nijave 2y agoMaybe I'm missing something obvious but that seemed to be the only option for injecting stub implementations in integration tests.
- mikeschinkel 2y agoInterfaces are one way to inject stubs, and a good way, but not the only way. You can also use function values as callbacks.
- roncesvalles 2y agoI prefer the testing libraries that do monkey-patching and consider mock implementations of interfaces to be an antipattern in Go, especially if it's the only reason for putting an interface between the calling code and a type.