Skip to content

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Aug 12, 2024

Motivation:

Naming is important; it should be clear and concise.

Modifications:

The follow renames all offer more precise names:

  • Rename server.run() to server.serve()
  • Rename server.stopListening() to server.beginGracefulShutdown()
  • Rename client.close() to client.beginGracefulShutdown()

Result:

Clearer APIs

@glbrntt glbrntt requested a review from gjcairo August 12, 2024 14:37
@glbrntt glbrntt added the version/v2 Relates to v2 label Aug 12, 2024
@glbrntt glbrntt enabled auto-merge (squash) August 12, 2024 14:37
/// - Note: You can only call this function once, repeated calls will result in a
/// ``RuntimeError`` being thrown.
public func run() async throws {
public func serve() async throws {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am a bit wary of renaming this from run to serve. While I understand what you are getting at. We do have many libraries that now adopted the run method name to align with what Lifecycle expects. If you rename this here and conform to Service in the future your type will have two methods that do the same.

Copy link
Collaborator

@gjcairo gjcairo Aug 13, 2024

Choose a reason for hiding this comment

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

FWIW I agree with Franz here, I think it is more important to be consistent with the rest of the ecosystem on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

run is less clear and is worse for users which don't depend on lifecycle. Users would have to provide shims to use Lifecycle anyway (to avoid retroactive conformance). If we provide conformance in the future (e.g. via package traits) then having a run() method calling through to serve() isn't an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the perspective of a user using Lifecycle the names of these methods don't matter at all because they won't be called directly by the user.

From the perspective of a user not using Lifecycle, these methods matter a lot: they will be called by the user so they should be clear.

Copy link
Collaborator

@FranzBusch FranzBusch Aug 14, 2024

Choose a reason for hiding this comment

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

I still remain unconvinced. serve and run are pretty close in my mind. Even leaving Lifecycle aside just the proliferation of run methods across the ecosystem is IMO enough to justify aligning. It becomes very natural that you call run on your server/clients when you don't use something like Lifecycle.

I don't want to block this PR on this and you can merge over my unconvincedness.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted. I'm pretty strongly against aligning for the sake of aligning on a generic name: I think we should pick names that express their intent and provide the most clarity, the APIs should be approachable for all users including those new to Swift and SoS!

///
/// Calling this on a server which is already stopping or has stopped has no effect.
public func stopListening() {
public func beginGracefulShutdown() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Motivation:

Naming is important; it should be clear and concise.

Modifications:

The follow renames all offer more precise names:
- Rename `server.run()` to `server.serve()`
- Rename `server.stopListening()` to `server.beginGracefulShutdown()`
- Rename `client.close()` to `client.beginGracefulShutdown()`

Result:

Clearer APIs
@glbrntt glbrntt force-pushed the naming-improvements branch from 267f7ba to c6336bb Compare September 4, 2024 08:36
@glbrntt glbrntt merged commit a06ade3 into grpc:main Sep 4, 2024
15 of 17 checks passed
@glbrntt glbrntt deleted the naming-improvements branch September 4, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version/v2 Relates to v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants