Skip to content
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

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

DimitrisJim
Copy link
Contributor

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.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@DimitrisJim DimitrisJim added the type: code hygiene Clean up code but without changing functionality or interfaces label Apr 12, 2023
@@ -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)
Copy link
Contributor Author

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.

Copy link
Contributor

@chatton chatton left a 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!

Copy link
Contributor

@crodriguezvega crodriguezvega left a 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)
Copy link
Contributor

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. :)

@crodriguezvega crodriguezvega merged commit 1ebf293 into main Apr 13, 2023
@crodriguezvega crodriguezvega deleted the jim/interface_conformance branch April 13, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code hygiene Clean up code but without changing functionality or interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants