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

Adopt official Java code format #60

Open
cpurdy opened this issue May 19, 2023 · 9 comments
Open

Adopt official Java code format #60

cpurdy opened this issue May 19, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@cpurdy
Copy link
Collaborator

cpurdy commented May 19, 2023

Is your feature request related to a problem? Please describe.
The only "problem" is a potential difficulty for developers who are not already familiar with the current code formatting.

Describe the solution you'd like
Use Java's code format standards, as described in Java Code Conventions

Suggestion: Some combination of auto-reformatting tools, plus manual review.

Suggestion: Add a check to CI pipeline to check formats.

Describe alternatives you've considered
There are infinite alternatives, which is to say there are no alternatives.

Additional context
Current code style is "Tangosol". It's a frequent topic of objection from people used to the common style used by Java and other languages (to save vertical space on their teletypes).

@cpurdy cpurdy added the enhancement New feature or request label May 19, 2023
@ggleyzer
Copy link
Collaborator

Are we ready to follow the above referenced conventions to the letter? Or we want just pick and choose whatever we like and ignore what we don't?

For example: Section 10 recommends parenthesis in multi-condition ifs:

... you shouldn’t assume that other programmers know precedence as well as you do ...
if (a == b && c == d) // AVOID!
if ((a == b) && (c == d)) // RIGHT

The standard Java classes definitely don't heed this advice.

The rules about the blank lines (5.1.2 Single-Line Comments) also are not followed.

@lagergren
Copy link
Contributor

lagergren commented May 19, 2023 via email

@cpurdy
Copy link
Collaborator Author

cpurdy commented May 19, 2023

The goal is to make it comfortable for people who currently use Java (etc.) to read Ecstasy code. I guess this might be worse also for some C# programmers (since Microsoft uses a similar style to old-Ecstasy, which isn't too surprising since I think we based our style design in the early 90s on what we saw working well in Windows C development at the time.)

We can augment the style guide with specific points. The {} required one is a good choice, for example (and we always use that already).

@lagergren
Copy link
Contributor

lagergren commented May 20, 2023 via email

@lagergren
Copy link
Contributor

lagergren commented May 20, 2023 via email

@cpurdy
Copy link
Collaborator Author

cpurdy commented Jun 2, 2023

Developed a one-time use tool for doing the code conversion of .x files:
https://github.com/xtclang/xvm/blob/master/javatools/src/main/java/org/xvm/tool/Reformat.java

So far, applied to the lib_ecstasy and javatools_bridge libraries.

@cpurdy
Copy link
Collaborator Author

cpurdy commented Jun 2, 2023

Completed applying reformatting tool to all xtclang/xvm .x files (libraries and examples). Gene is converting tests. Other projects (such as platform) will need to be updated as well.

@lagergren we should be able to use an existing tool to do the same reformatting job for the Java code. Any experience with any of them?

@lagergren
Copy link
Contributor

Yes, I have experience with checkstyle and spotless.

Typically the former checks the syntax, and the spotlistApply gradle build task applies the changes.

Best practise is to continue by adding a git hook so the checks run automatically every commit so you don't have to. Typically I only use this as a verification for a finished pull request when it goes into master. Normally it's just invoked from all local builds (without applying the spotless code changes).

I'd be happy to set this up in a few weeks when the language support is good enough.

The advantage with these tools is that they can very easily be extended with our existing XTC grammar, to also support an XTC code standard for any XTC projects in our builds!

(see: https://medium.com/@anirudhramesh95/enforcing-formatting-standards-for-your-java-project-using-gradle-2c21172743e5)

/M

@cpurdy
Copy link
Collaborator Author

cpurdy commented Jul 31, 2023

Let's just make sure to completely "sew up the current patient" (the currently in-flight build changes) first before getting onto this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants