-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nit: Use nil pointer pattern to check for interface compliance. #3439
Conversation
@@ -11,7 +11,7 @@ import ( | |||
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" | |||
) | |||
|
|||
var _ types.QueryServer = Keeper{} | |||
var _ types.QueryServer = (*Keeper)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to revert the changes on types implementing interfaces using value receivers if it generally gives the impression (unsure) they must be used as pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the nil
version is more efficient, but the gains here would be so inconsequential that I think the decision made should be one that favours readability over performance.
I personally find the struct literal syntax more readable/intuitive, however I don't feel that strongly about it. Consistency is more important to me than the actual style we choose.
Happy to go forward with this style if that is the preference people have!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @DimitrisJim. :)
_ sdk.Msg = (*MsgChannelCloseConfirm)(nil) | ||
_ sdk.Msg = (*MsgRecvPacket)(nil) | ||
_ sdk.Msg = (*MsgAcknowledgement)(nil) | ||
_ sdk.Msg = (*MsgTimeout)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you grouped all these together. :)
Description
Reference: #3437 (comment)
To use a consistent style between creating an empty struct and taking its reference vs. casting a nil pointer to the type.
For types implementing interfaces using value receivers this works in exactly the same way since a pointer to that type is also considered as implementing the interface.
I'm hopeful I got most of them.
closes: #XXXX
Commit Message / Changelog Entry
nit: Use nil pointer pattern to check for interface compliance.
see the guidelines for commit messages. (view raw markdown for examples)
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
).godoc
comments.Files changed
in the Github PR explorer.Codecov Report
in the comment section below once CI passes.