Skip to content

Proposal: Refactor server_dap to use command-registration style #931

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

Closed

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Mar 17, 2023

The current implementation of server_dap.rb uses a very long case statement.

We (the Ruby Developer Experience team at Shopify) would like to propose changing this better align with the register_command approach already used in sessions.rb. This will allow the long case statement to be avoided, and will provide better consistency within the project.

Please take a look at a suggested approach. The behaviour should be identical to as it was before. We look forward to hearing your feedback.

We recommend viewing the PR with whitespace changes ignored: https://github.com/ruby/debug/pull/931/files?w=1

@andyw8 andyw8 changed the title Refactor server_dap to use command-registration style Proposal: Refactor server_dap to use command-registration style Mar 17, 2023
@andyw8 andyw8 marked this pull request as ready for review March 17, 2023 19:54
@ko1
Copy link
Collaborator

ko1 commented Mar 22, 2023

Thank you for the patch.
However, current usage of case/when is intentional and consistency is not acceptable reason.
I will close it if there is no reasons.

@andyw8
Copy link
Contributor Author

andyw8 commented Mar 30, 2023

@ko1 Thank you for the feedback. I will give some additional context about why we wanted to make this change:

Within the Shopify Ruby DX team, we aim to build a better understanding of how Shopify developers are using tooling, by adding telemetry/metrics reporting.

For debug, we want to learn which particular commands developers are making use of. Our idea was to override the process method in our applications to allow this. However, since the process method is very long, that would be difficult to maintain, hence we wanted to first refactor.

We are curious, what's the reason for preferring case here, but the registration approach in sessions.rb?

Regardless, there is a different approach we could take that would result in a much smaller change. We could extract the body of the while into a separate method, which would make it much easier to override process:

def process
  while req = recv_request
    process_request(req)
  end
end

def process_request(req)
  case req['command']
    when 'launch'
    # ...
    # etc. for all the existing `when` clauses
  end
end

Would you be open to something like that?

@andyw8
Copy link
Contributor Author

andyw8 commented Apr 11, 2023

@ko1 Just wondering if you have any further thoughts on this?

@ko1
Copy link
Collaborator

ko1 commented May 4, 2023

However, since the process method is very long, that would be difficult to maintain, hence we wanted to first refactor.

I don't think "difficult to maintain" on this case but it is my preferences.
Trivial reason is case/when with strings will be compiled to special optimized bytecodes so it is slight faster.

Regardless, there is a different approach we could take that would result in a much smaller change. We could extract the body of the while into a separate method, which would make it much easier to override process:

It is acceptable so I'll make another PR for it and close this PR. Thank you.

@ko1 ko1 closed this May 4, 2023
ko1 pushed a commit that referenced this pull request May 4, 2023
and we can intercept each requests.

See #931
ko1 pushed a commit that referenced this pull request May 4, 2023
and we can intercept each requests.

See #931
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