News for hackers. Stuff that matters.
Re:Go: What We Got Right, What We Got Wrong by bb88 on Thursday January 04, 2024 @06:41PM (#38873787)
But don't those exist primarily for unit testing? That was my understanding of why interfaces were there.

If you wanted a mock, you needed an interface, even if there would ever only be one implementation of it in production.

Re:Go: What We Got Right, What We Got Wrong by tormeh on Thursday January 04, 2024 @10:09PM (#38875268)
I hate this pattern. Needless indirection for insignificant benefit.
Re:Go: What We Got Right, What We Got Wrong by akoboldfrying on Friday January 05, 2024 @12:01AM (#38875877)
It's indeed horrible when debugging. OTOH, there's merit to the idea that better testing means less overall time spent (on either testing or debugging), so design choices that make testing easier provide a gain -- provided that good tests are actually implemented.
Re:Go: What We Got Right, What We Got Wrong by bb88 on Thursday January 04, 2024 @11:46PM (#38875780)
Golang "punishes" you for wanting to write a unit test around code.

You need to refactor it to use an interface just to unit test it.

Re:Go: What We Got Right, What We Got Wrong by sidlls on Friday January 05, 2024 @01:00AM (#38876187)
No, you don’t, unless you’re of the opinion that actual data structures with test data should not be used in a unit test.
Re:Go: What We Got Right, What We Got Wrong by bb88 on Friday January 05, 2024 @01:59PM (#38883129)
I think you're missing the point here.

Duck typing with python (e.g.) makes it easy to mock a class. One can subclass a Java class to make a mock, etc.

One can't do that in golang unless it's through an interface which then decouples tightly coupled code because [golang reasons].

Re:Go: What We Got Right, What We Got Wrong by zimpenfish on Friday January 05, 2024 @03:55AM (#38877087)
> But don't those exist primarily for unit testing?

I believe that's why people insert them everywhere, yes, but in the codebases I'm talking about, many (I'd say the majority, to be honest) of the interfaces aren't used for testing because they've just been cargo-culted rather than actually considered.

(Obviously this is with hindsight - they may well have been considered at the time but the end result doesn't reflect that.)