| ▲ | the_gipsy 2 days ago | ||||||||||||||||||||||||||||||||||
Yes, this is exactly the problem with go's recipe. Either you copypaste the same interface over and over and over, with the maintenance nightmare that is, or you always have these struct-and-interface pairs, where it's unclear why there is an interface to begin with. If the answer is testing, maybe that's the wrong question ti begin with. So, I would rather have duck typing (the structural kind, not just interfaces) for easy testing. I wonder if it would technically be possible to only compile with duck typing in test, in a hypothetical language. | |||||||||||||||||||||||||||||||||||
| ▲ | 9rx 2 days ago | parent [-] | ||||||||||||||||||||||||||||||||||
> I wonder if it would technically be possible to only compile with duck typing in test Not exactly the same thing, but you can use build tags to compile with a different implementation for a concrete type while under test. Sounds like a serious case of overthinking it, though. The places where you will justifiably swap implementations during testing are also places where you will justifiably want to be able to swap implementations in general. That's what interfaces are there for. If you cannot find any reason why you'd benefit from a second implementation outside of the testing scenario, you won't need it while under test either. In that case, learn how to test properly and use the single implementation you already have under all scenarios. | |||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||