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

Consider using idiomatic capitalization in backend interface #11582

Closed
dae opened this issue Jun 10, 2022 · 5 comments · Fixed by #16815
Closed

Consider using idiomatic capitalization in backend interface #11582

dae opened this issue Jun 10, 2022 · 5 comments · Fixed by #16815
Milestone

Comments

@dae
Copy link
Contributor

dae commented Jun 10, 2022

DroidBackend is currently a mix of snake_case and camelCase names. Presumably the former was picked to more closely match the Python and Rust code, but I'd humbly suggest it would be better to use the more idiomatic camelCase, as that is less surprising, and will let you avoid editor warnings. Anki's TypeScript code uses camelCase too, as does the default codegen for protobuf files in Kotlin/Java.

@david-allison
Copy link
Member

I'd like to reopen this for discussion

It feels useful to have the Anki code which mirrors the python be 1:1 in all aspects.

One of our constant maintenance tasks will be to match Anki Desktop's python, and we want this to be done as easily as possible.

With Kotlin, we can get very close to matching the syntax of the python.

Everything else: Absolutely go with idiomatic code.

One of my long-term goals (once we're back to parity) would be linking the files to the Anki Desktop hashes so we ensure we don't miss changes going forwards.

@dae
Copy link
Contributor Author

dae commented Jul 22, 2022

My thinking here is that most of the time, developers are not concerned with the intricacies of the backend, and they expect functions/properties to be in the format typical of that language. When developers do need to compare things to the desktop code, it's fairly easy to convert a camelCase name to a snake_case name in your head, and the conversion is unambiguous. Given that the desktop code is a mix of the formats itself (Rust/Python use snake_case; TypeScript uses camelCase; the protobuf definitions use PascalCase for methods, snake_case for properties, and SCREAMING_CASE for enum cases), I'm not sure you could even claim that one format is canonical. Presumably that's the view the protobuf developers took too - the generated Java/Kotlin code uses idiomatic casing instead of trying to match the protobuf definitions.

@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the Stale label Sep 20, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2022
@david-allison david-allison reopened this May 5, 2024

This comment was marked as outdated.

@david-allison
Copy link
Member

Conclusion:

  1. camelCase is better for the majority of developers
  2. snake_case names are better for developers who are working inside the files, to match functionality with upstream

camelCase should be used by default

An annotation has been added @LibAnkiAlias("is_empty"), to handle (2).

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 a pull request may close this issue.

2 participants