Would appreciate some feedback on a naming issue my team has been 
struggling with recently.

We sometimes use interfaces for mocking in tests, as described in this 
blogpost: 
https://nathanleclaire.com/blog/2015/10/10/interfaces-and-composition-for-effective-unit-testing-in-golang/.

The naming issue is *what* convention we should use for naming the 
interface and the main code struct (we see no issue in prepending "mock" or 
"test" in the test struct), since they cannot be equal.

In the blogpost, the interface suffixes "er" even when it reads poorly, but 
I can see the value in the convention adding to the readability, which we 
value the most.

Other options we've discussed are:

(1) prefixing a letter on the interface, forcing the team to remember a 
convention largely unseen in code we've used e.g. iConsumer/consumer.
(2) uppercasing the interface in cases when it's obvious the package is 
never going to be imported anyway, but nevertheless changing a 
well-established golang semantic e.g. Database/database
(3) adding a word that doesn't hurt and provides more info to what that 
struct does, even if it doesn't make the differentiation between the two 
more clear nor one plans different implementations e.g. 
endpoint/httpEndpoint.

All options are tradeoffs and we haven't really agreed on one.

Our main goal is readability and consistency.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to