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

Add a static factory method to create the stub #163

Closed
asarkar opened this issue Aug 18, 2020 · 4 comments
Closed

Add a static factory method to create the stub #163

asarkar opened this issue Aug 18, 2020 · 4 comments

Comments

@asarkar
Copy link

asarkar commented Aug 18, 2020

The usual way to create a client stub in Java is using one of the static factory methods named new*Stub. Consider adding such a method for consistency instead of invoking the constructor directly.

@lowasser
Copy link
Collaborator

What would this really buy us, though? Using the constructor is more conventional for Kotlin, and we can't add the static method to the same place that Java's would be, so having a "static" (companion?) factory doesn't seem to actually provide much benefit.

@asarkar
Copy link
Author

asarkar commented Aug 19, 2020

@lowasser It just makes it easier for people already familiar with grpc-java by following the same convention. The Java constructors are, in fact, private, and hence, can’t be invoked directly. Does it make sense to introduce a new paradigm in the Kotlin counterpart? Also, the choice of constructor vs static method isn’t a language choice, it’s a design choice; Java could’ve simply exposed the constructors but didn’t.

@lowasser
Copy link
Collaborator

There is a difference in what is idiomatic in Kotlin versus Java, and idiomatic Kotlin tends more towards the use of constructors.

In any event, I don't think we want to provide two ways of doing the same thing at this point.

@asarkar
Copy link
Author

asarkar commented Aug 25, 2020

I don't think we want to provide two ways of doing the same thing

Just to be clear, I wasn't suggesting having two ways, but making the constructor private and creating a static factory method in order to be more consistent with the Java generated code. Using the constructors may be your personal preference, but I've not heard that Kotlin prefers constructors over static methods as a general design principle.

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

No branches or pull requests

2 participants