Re:Go Is a Well-Designed Language
by roncesvalles on Friday January 31, 2025 @01:56PM
(#42890483)
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.
[ Parent
| on HN ]
Maybe I'm missing something obvious but that seemed to be the only option for injecting stub implementations in integration tests.
Re:Go Is a Well-Designed Language
by mikeschinkel on Saturday February 01, 2025 @12:56AM
(#42896059)
Interfaces are one way to inject stubs, and a good way, but not the only way. You can also use function values as callbacks.
Re:Go Is a Well-Designed Language
by roncesvalles on Saturday February 01, 2025 @04:44AM
(#42897194)
I 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.