The craft of interfaces

Currently I am reading 100 Go Mistakes and I like it. One of my personal pet peeves is the ‘interface on the producer side’. It’s a sure way to spot a programmer who is new to Go. And that makes me think again on how to mentor new Go programmers. I remember myself struggling with that when starting out. Today most of the idiomatic Go is widely documented and newbies still struggle with that. Should the language itself enforce these ‘mistakes’? Some can be enforced by linters but not all. And even with the ‘interface on the producer side’ mistake there are exceptions where it could make sense to share an interface between consumers and maybe even put it on the producer side. That’s the ‘art’ of the craft. I got asked once by a developer coming from .NET: “Why are these idiomatic rules not written down somewhere?”. I guess because it’s kind of an oral tradition. Similar to the (horribly named) ‘code smells’. It’s a taste imprinted by practice and reading lots of ‘good’ Go code. When working with AI I try to provide unit tests and interfaces before I let it generate the actual function. I saw too much one-shot code that was not testable and horribly un-idiomatic. The interface and the unit test act as the spec and help me get what I want out of the LLM. I still care about code quality so that might just be me.

Enjoyed this post or have feedback?
← 154 Legacy