The official Java style and convention for Sponge

We’ve established some more complete and official style guidelines for Sponge.

It is largely following in the footsteps of Google’s Java style.

This replaces the rules previously mentioned in the Contribution Guidelines document.

15 Likes

sk, a lot of people are still missing this thread :(. Therefore continuing to break guide lines and having a @turt2live rampaging all over them :stuck_out_tongue: <3 turt

My mailbox are exploding xD
Good work @turt2live

Could one create a format profile for eclipse?

I’ve followed this tutorial to create a eclipse formatter profile from the checkstyle.xml.

EDIT: I’ve created a pull request for this, where you can also view the settings.xml file

2 Likes

Yay for coding standards!

(particular yay for coding standards I like! :slight_smile: )

Check your PR. Few missing styles from checkstyle itself but are from the usual coding conventions

I’ve updated the PR. Thanks for you review!

1 Like

I always learned constants in Java should be all uppercase letters.
Google Java Style also uses this style: https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.2.4-constant-names

This is what I found in the Sponge Style Guidelines:

private static final Logger log = Logger.getLogger(ExampleClass.class);
private static final Random random = new Random();
private final String id = "test";

@sk89q Is this suppose to be?

The section of documentation you linked includes almost the same examples as those you quote - those aren’t considered constants because either they are mutable (log and random), or they’re not static (id).

1 Like

Good to have new guidelines for code. Previous one wasn’t very clear in all cases.

Okay, thanks for clearing that out!

So when using the Sponge Style Guidelines, this would be in uppercase letters?

static final int NUMBER = 5;

Yes, that’s still uppercase because it’s all three of static, final, and immutable (cannot be changed by calling methods on it).