chasm icon indicating copy to clipboard operation
chasm copied to clipboard

Code Style

Open CheaterCodes opened this issue 3 years ago • 8 comments

We are in desperate need to get some uniform code style, at least for this repository.

Requirements would be:

  • Automated checks possible (ideally via gradle)
  • Integration in Intellij
  • Integration in Eclipse

Checkstyle comes to mind, I think it has good support and should be sufficient. We don't need anything super specific, but just having standards on general formatting and imports would be good.

CheaterCodes avatar Nov 18 '21 10:11 CheaterCodes

I've added a checkstyle file and the gradle plugin. This should probably be mentioned in a CONTRIBUTING.md file.

I would still like to add a github workflow to check the style of prs. If anyone could help with that, that'd be great!

Also the checkstyle right now is a sliightly modified version of the google style from the checkstyle repo. If anyone who knows what they are doing would like to modify that, please do!

Lastly, no promises that the editorconfig matches the checkstyle.

CheaterCodes avatar Nov 18 '21 17:11 CheaterCodes

How do we want to handle boxing and unboxing? I like to explicitly use Integer.valueOf and .intValue(), but I've also seen casting to Object and casting to int, or leaving the (un)boxing implicit.

cplir-c avatar Nov 19 '21 20:11 cplir-c

I think that implicit unboxing, like I used everywhere else in the project, is absolutely fine.

CheaterCodes avatar Nov 19 '21 20:11 CheaterCodes

Streams are probably fine until they're in a performance-critical area, then it should be benchmarked. I'll put them back in my PR. Unless they're not more readable than for loops?

cplir-c avatar Nov 23 '21 03:11 cplir-c

Until we have any idea how critical performance is we should just choose whatever is more readable. And I highly doubt streams will matter in chasm, in terms of performance.

I think streams are good to read if the operations are fairly short:

  • Filter and get first
  • Filter and collect
  • Map and collect

CheaterCodes avatar Nov 23 '21 03:11 CheaterCodes

I've added a checkstyle file and the gradle plugin. This should probably be mentioned in a CONTRIBUTING.md file.

I would still like to add a github workflow to check the style of prs. If anyone could help with that, that'd be great!

Also the checkstyle right now is a sliightly modified version of the google style from the checkstyle repo. If anyone who knows what they are doing would like to modify that, please do!

Lastly, no promises that the editorconfig matches the checkstyle.

This is sadly an annoyance of the entire java tooling ecosystem not having any real good formatters beyond the IDEs, which is something that will raise controversy if we force everyone to use some specific IDE.

i509VCB avatar Nov 24 '21 02:11 i509VCB

Yeah I keep forgetting about the CONTRIBUTING.md file.

In other notes, I added an action that automatically builds PRs, which also runs checkstyle. Sorry for not mentioning that here before.

CheaterCodes avatar Nov 24 '21 06:11 CheaterCodes

We don't want to use var for Java 8 compat, right? Should we use this. instead of just ? Would it be the same for methods? I prefer using this because I think it's more explicit, so you can tell whether you're using a local variable or a field.

cplir-c avatar Dec 01 '21 06:12 cplir-c