-
Notifications
You must be signed in to change notification settings - Fork 123
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
[Enhancement] Introduce C++ formatter in JNI. #2250
Comments
I typically refer to google's style guide. But I dont have a strong preference. Do you have one you like in particularly?
It seems spotless supports it: https://github.com/diffplug/spotless. Would we be able to leverage gradle to do this so we dont have to worry about dependencies?
This is unfortunate but a one time cost. I think its okay. |
I really don't care haha. But, the google style is the most comfortable for me. |
Nice!! then we can decouple formatting from CMake entirely ONLY IF it can format as much as clang-format. |
Looks like
|
I think we can also consider eclipse CDT formatting with Google code style : https://github.com/google/styleguide/blob/gh-pages/eclipse-cpp-google-style.xml
Result:
|
@0ctopus13prime did you get a poc working? If so Im good with google guide and eclipse |
Sure, let me raise a PR shortly. I'm planning to start working on this after bumping up JNI C++ version to 17. |
@jmazanec15 FAISS uses snake_case for method names (NMSLIB uses camelCase, but that's going to be deprecated in the future anyway). The Google C++ style guide uses PascalCase for method names (e.g.,
|
In general, I think PascalCase is fine. I dont think we need to align with any libraries. We just need to make sure our conventions are consistent. |
@jmazanec15 |
Enabled C++17 in JNI, will continue working on this. |
Eclipse CDT mostly works but it's not perfect. Seems struggling when parsing template
I'm inclining toward |
After running clang-tidy with Google code style on our JNI codes, I got around 330 warnings (excluding faiss and nmslib). |
sounds good! So, would gradle not auto-configure dependency? |
@jmazanec15 |
Description
Currently, we don’t have a formatting tool enabled for C++ code, and as a result, the codebase has a mix of different coding styles. In contrast,
spotless
is already enabled for Java, preventing builds if code does not follow the established format. I propose adopting a similar approach for our C++ (JNI) code.Establishing a consistent code style for C++ in our repository would enhance readability and facilitate future collaboration. Allowing multiple styles to coexist can lead to the "Broken Windows Effect," where visible inconsistencies invite further deviations, ultimately contributing to a less organized and harder-to-maintain codebase.
Tools
After researching several options, I propose setting up
clang-format
, which is compatible across major platforms—Linux, macOS, and Windows. The tool is also easy to integrate with popular IDEs like CLion, VSCode, and others, makingclang-format
a straightforward choice for our needs.Note : We can also consider to use spotless - https://github.com/diffplug/spotless
Code Style
The key principle is to adopt a unified and widely accepted code style that maintainers prefer. Naturally, auto-generated JNI method signatures will remain unchanged, even after introducing the formatter, as the method naming pattern is a contract that the JVM relies on to locate the methods it calls.
I want to put it on a vote:
Required Changes
General idea is to make Makefile generated by CMake to call
clang-format
to format C++ codes.I prefer this approach since I like a system to take care of choirs by itself, but open to other approaches.
Or, alternatively we can make it reject to build if it found there are misformatted files similar to what we are doing in Java.
Once it's rejected, user must run formatting manually before building.
Expected Hassle
Since it requires
clang-format
, we need to overhaul all the pipeline, CI infra had it already to avoid program not found exception during building.So I'm proposing 2 stages of introduction:
1st phase : Introduce formatting, but run it only if the program exists.
2nd phase : After make sure that pipelines, CI and other major third party won't have issue with formatting, we can enforce the formatting.
Merge conflicts
Since it is expected to bring changes most files, all changes before formatting in dev branch will likely hit merge conflicts.
The text was updated successfully, but these errors were encountered: