Best practices for empty interfaces in Go?

I am learning about empty interfaces. I find that while there are many explanations—also on Stackoverflow—on meaning of an empty interface and how they work, there's very little information on best-practices on when / why to use them, when to avoid, what the considerations are, and the pros and cons of chosing to use them.

In Go chatrooms I've read some talk about best to avoid using empty interfaces where possible, but without the proper arguments. Others proudly responding they had zero empty interfaces in their code design.

I am most interested in use for go-gettable modular libraries and frameworks.

Right now I am reading a framework codebase with related libraries, that is full of emtpy interfaces in many locations. Some of this confuses me, and I wonder if all usages are warranted. Like the framework offers 'user management' and things like AppConfiguration and UserPreferences are empty interfaces. This while further on in the code (near the db layer) the user's email is technically treated as a user preference. Wouldn't it be better to be more specific in the interface definition?



Read more here: https://stackoverflow.com/questions/65717232/best-practices-for-empty-interfaces-in-go

Content Attribution

This content was originally published by Arnold Schrijver at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: