-
Notifications
You must be signed in to change notification settings - Fork 60
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
Naming of methods and constructors #585
Comments
If you have The next question is which constructor gets to be just An alternative could be going by number of arguments, and have (Would you worry about sorting in APIs if you get above A completely different approach could be to try to derive a name from the parameter type, like I definitely don't like The |
Agreed.
That would create a lot of unnecessary leading digits for constructors and methods that otherwise don't even have a same-named counterpart.
Yes, especially since Java is not known for short parameter type names either: |
One general problem with numbers is that they can move around when for example the new version of the library comes with added methods. And users must update their code to reflect this change. We even had this issue before: #696 One way of fixing this is to use some hashed version of argument names at the end of the method name. This is 1. ugly and 2. Requires ALL methods to end with this hash. |
In FFIgen we've also gone with the numbering, so far we've not had too many issues with renumbering there. Though it might be that it's more common in Java libs?
This is what I use in the generated tests for FFI as well. But it's ridiculously long method (and in that case class) names. Those long names really only work in that situation because all the call-sites are generated as well. Not sure if hashes are better or worse. 🙊 But at least both approaches are stable. Maybe some kind of compromise is the name-postfix / hash from the moment we see two method names. In that case there's only ever 1 migration for users, instead of multiple as with renumbering. A completely different approach would be to read in the yaml file that we generate, and use that to keep the renumberings from jumping around. (However, that makes JNIgen unstable if it is run on the same API in a clean project later...) |
Java classes can have multiple (unnamed) constructors. Currently we name the other constructors as
ctor1
,ctor2
, ... . I propose changing the names tonew1
,new2
, ... .Rationale: Currently if we have multiple Java methods with the same name like
foo
, we name them asfoo
,foo1
,foo2
, ... meaning we could write:Similarly we could
@dcharkes @mahesh-hegde @lrhn Any better idea for naming multiple constructors / methods instead of the added number? Do you like
ctor
ornew
better?The text was updated successfully, but these errors were encountered: