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

avoid type assertion on Action/Auth in switchs #311

Closed
wants to merge 1 commit into from

Conversation

najeal
Copy link
Contributor

@najeal najeal commented Jul 27, 2023

@patrick-ogrady I am not a big fan of switching from type assertion to GetTypeID() usage in switch statement.

  1. in cases we often use the type assertion.
  2. type assertion is faster than reflection we deleted in create TypeID for Actions/Auths + delete reflection in Registry #297
  3. it makes code more difficult to read

switch action := tx.Action.(type) { //nolint:gocritic
case *actions.Transfer:
switch tx.Action.GetTypeID() { //nolint:gocritic
case (&actions.Transfer{}).GetTypeID():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was thinking you just would do:

case TransferTypeID:

Copy link
Contributor

@patrick-ogrady patrick-ogrady Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the way it is now (with your current change) is way more confusing/less clean

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 thought about doing it but it makes potentially use a declared ID not used by any Type.
The both were possible.

case *actions.Transfer:
switch tx.Action.GetTypeID() { //nolint:gocritic
case (&actions.Transfer{}).GetTypeID():
action := tx.Action.(*actions.Transfer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't think about the need to do this...probably better to just leave for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can close this PR and disregard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants