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

Java style enforcement #24

Open
GreyCat opened this issue Jan 26, 2020 · 3 comments
Open

Java style enforcement #24

GreyCat opened this issue Jan 26, 2020 · 3 comments

Comments

@GreyCat
Copy link
Member

GreyCat commented Jan 26, 2020

Given that our Java codebase grows, I guess it's time to decide on a certain coding style and stick to it.

Historically, Java coding style guidelines were slightly better than total anarchy of C++, but still pretty ambiguous. As far as I understand, the only current tool which performs the enforcement is checkstyle, and it offers two options:

"Sun style" seems to be very ambiguous and checks almost nothing, and "Google style" seems to be pretty strict, but it's mandating 2 spaces indent.

I was thinking of adopting Google style with one exception of using 4 spaces indent (as it seems to be the default in most Java environments).

This will be beneficial both for this Java runtime project and kaitai_struct_gui.

@Mingun, @ams-tschoening — any ideas / preferences?

@ams-tschoening
Copy link
Contributor

I don't like too strict guidelines, people should be allowed to decide that some pieces of code are more readable the way they are even if not following strict guidelines. Did work with some version of the Google-guidelines some years ago and was forced to reformat all code automatically by the IDE and the results were really often very unreadable, e.g. because things were placed entirely on the right side of the monitor, spanning multiple lines and stuff like that.

From my experience there's no formatter and guide able to handle every piece of code, therefore every strict enforcement will fail. In my opinion it's better to trust developers that they want to create readable code and people should be allowed to change their minds. So only discuss some rough guidelines like tabs vs. spaces, indentation size, where brackets are, spaces before/after brackets and stuff like that, but don't enforce too much.

@Mingun
Copy link
Contributor

Mingun commented Feb 3, 2020

I agree with @ams-tschoening, that too strict guidlines are not necessary. But I will agree that it looks reasonable to record the bracket placement rules and the size of the indents. I have nothing against the 2-space indents, moreover, they seem more sympathetic to me, but I will not insist.

The rest of the rules would apply with caution. However, it can be noticed that Java community is quite conscious and everyone adheres to the same style as a whole.

So only discuss some rough guidelines like tabs vs. spaces, indentation size, where brackets are, spaces before/after brackets and stuff like that, but don't enforce too much.

Totally agree.

@ams-tschoening
Copy link
Contributor

Things like tabs vs. spaces etc. can easily be achieved already using EditorConfig already, that might be low hanging fruits. More detailed formats need to be supported by various IDEs for example, EditorConfig is available almost everywhere.

Besides that, I used Astyle pretty successfully to style codebase of log4cxx in the past. Might be worth a look as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants