cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

[Code Style] Appropriate suffix/prefix for interface definitions

Open Olshansk opened this issue 3 years ago • 4 comments

Various interfaces in the codebase, such as AccountKeeperI are implemented with the I as a postfix.

Screen Shot 2022-09-12 at 6 07 23 PM

I couldn't find official Golang guidelines, but this post suggests:

Screen Shot 2022-09-12 at 6 08 04 PM

And Dave Cheney's Practical Go uses the same pattern:

Screen Shot 2022-09-12 at 6 08 32 PM

Is it fair to assume that this is just a legacy thing someone did that stuck around or is there an explicit reason for this design pattern?

Olshansk avatar Sep 12 '22 22:09 Olshansk

I'm not opposed to renaming interfaces that have the I suffix 👍

I think I added these way back then when I didn't know this existed.

alexanderbez avatar Sep 13 '22 07:09 alexanderbez

Should be a straightforward PR with a few global find/replace operations. I'm happy to submit a PR with the changes.

Just wanted to make sure I have a 👍 to replace type (.*)[a-z]I interface \{ with type I(.*)[a-z] interface \{ throughout the codebase before I spend time making the changes and running the tests.

Screen Shot 2022-09-13 at 9 28 57 AM

Olshansk avatar Sep 13 '22 13:09 Olshansk

Sure @Olshansk! Thanks :)

alexanderbez avatar Sep 13 '22 15:09 alexanderbez

Sounds great :)

https://github.com/cosmos/cosmos-sdk/pull/13268

Olshansk avatar Sep 13 '22 23:09 Olshansk

https://medium.com/@dotronglong/interface-naming-convention-in-golang-f53d9f471593

This guidance is incorrect.

peterbourgon avatar Oct 30 '22 04:10 peterbourgon

Closing as per https://github.com/cosmos/cosmos-sdk/pull/13268#issuecomment-1296096676

julienrbrt avatar Oct 30 '22 09:10 julienrbrt