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

Simplify code gen lib interface #2169

Merged
merged 3 commits into from
Jan 23, 2025
Merged

Simplify code gen lib interface #2169

merged 3 commits into from
Jan 23, 2025

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jan 22, 2025

Motivation:

When reviewing APIs I noticed a few inconsistencies and some abstractions which are more complicated than they need to be. We should simplify this before we commit to a stable API.

Modifications:

  • Replace the 'Name' type with a more concrete 'ServiceName' and 'MethodName'. They carry approximately equivalent information but the information is expressed in terms of what the names are used for (i.e. a function vs. what the expected format of the name is, e.g. lowercase). This makes it easier for users to understand how the names will be used and leaves room for more customisation in the future.
  • The service descriptor used two names: a namespace name and a service name. These have now been compressed into a single object (not all namespace name values were used). The namespace name was never used in isolation so this was adding unnecessary complexity.
  • The top-level 'SourceGenerator' type has been renamed 'CodeGenerator'. This is consistent with being a 'CodeGen' module and having a 'CodeGenerationRequest'.
  • The closures for returning code snippets to create a serializer/deserializer were renamed to make their user clearer.
  • Accidental public API was removed.

Result:

Slightly smaller and more consistent API.

Motivation:

When reviewing APIs I noticed a few inconsistencies and some
abstractions which are more complicated than they need to be. We should
simplify this before we commit to a stable API.

Modifications:

- Replace the 'Name' type with a more concrete 'ServiceName' and
  'MethodName'. They carry approximately equivalent information but the
  information is expressed in terms of what the names are used for (i.e.
  a function vs. what the expected format of the name is, e.g.
  lowercase). This makes it easier for users to understand how the names
  will be used and leaves room for more customisation in the future.
- The service descriptor used two names: a namespace name and a service
  name. These have now been compressed into a single object (not all
  namespace name values were used). The namespace name was never used in
  isolation so this was adding unnecessary complexity.
- The top-level 'SourceGenerator' type has been renamed 'CodeGenerator'.
  This is consistent with being a 'CodeGen' module and having a
  'CodeGenerationRequest'.
- The closures for returning code snippets to create a
  serializer/deserializer were renamed to make their user clearer.
- Accidental public API was removed.

Result:

Slightly smaller and more consistent API.
@glbrntt glbrntt added the ⚠️ semver/major Breaks existing public API. label Jan 22, 2025
@glbrntt glbrntt requested a review from gjcairo January 22, 2025 10:39
Copy link
Collaborator

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

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

LGTM but one small comment

Comment on lines 299 to 306
let identifier = namespace.base.isEmpty ? name.base : namespace.base + "." + name.base

let upper =
namespace.generatedUpperCase.isEmpty
? name.generatedUpperCase
: namespace.generatedUpperCase + "_" + name.generatedUpperCase

let lower =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, but can we rename these variable names to identifyingName, typeName and propertyName?
Before looking at the tests, I was very confused about the names and what each was supposed to be 😅 (e.g. it's called lower but we use name.generatedUpperCase, etc).

Copy link
Collaborator Author

@glbrntt glbrntt Jan 22, 2025

Choose a reason for hiding this comment

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

Oh yes, of course. I'm not sure why I used upper and lower here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

btw, WDYT of identifyingName? I'm not 100% happy with it but wasn't sure about alternatives.

@glbrntt glbrntt merged commit e4f69cf into grpc:main Jan 23, 2025
26 of 29 checks passed
@glbrntt glbrntt deleted the v2/code-gen branch January 23, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ semver/major Breaks existing public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants