News for hackers. Stuff that matters.
Re:Too Much Go Misdirection by dgb23 on Monday May 19, 2025 @01:52PM (#44032628)
Personally I rarely use or even implement interfaces except some other part needs them. My brain thinks in terms of plain data by default.

I appreciate how they compose, for example when I call io.Copy and how things are handled for me. But when I structure my code that way, it’s extra effort that doesn’t come naturally at all.

Re:Too Much Go Misdirection by lanstin on Monday May 19, 2025 @07:16PM (#44036003)
I use them for testing, where I can have a client that is called by the code under test and can either just run a test CB, send a REST call to a remote server, send a gRPC call to a remote server, or make a function call to an in-process gRPC server object.
Re:Too Much Go Misdirection by __turbobrew__ on Monday May 19, 2025 @09:26PM (#44036838)
Yea, mocking is generally the most use I get out of interfaces
Re:Too Much Go Misdirection by dgb23 on Tuesday May 20, 2025 @01:08PM (#44043725)
Plain data is really convenient for testing though.

I think the reason that your example is so useful is not generally because of testing, but because the thing you're interacting with has operational semantics. It's a good use case for object orientation, so interfaces and mocking are the natural way of testing your logic.