|
2 | 2 |
|
3 | 3 | I've no clue how I managed to spend 3 years learning software development without using a proper IDE for developing larger projects. From the first days of FastJ I quickly realized I needed a rule set for how my code should be written. |
4 | 4 |
|
5 | | -- [IDE](#IDE) |
6 | | -- [Imports](#Imports) |
7 | | -- [General Code Style](#General-Code-Style) |
8 | | - - [Column Limit](#Column-Limit) |
9 | | - - [Block Indentation](#Block-Indentation) |
10 | | - - [Wildcard Imports](#Wildcard-Imports) |
11 | | - - [Annotations](#Annotations) |
12 | | - - [Constant Names](#Constant-Names) |
13 | | - - [Type Variable Names](#Type-Variable-Names) |
14 | | - - [Camel Case Defined](#Camel-Case-Defined) |
15 | | -- [API Documentation](#API-Documentation) |
16 | | - - [Be Clear](#Be-Clear) |
17 | | - - [Be Thoroughly Concise](#Be-Thoroughly-Concise) |
18 | | -- [Website Documentation](#Website-Documentation) |
19 | | - |
20 | 5 |
|
21 | 6 | ## IDE |
22 | 7 | I absolutely prefer that you use [IntelliJ IDEA][IntelliJ-Link] while developing FastJ, but [Eclipse][Eclipse-Link] is fairly capable of keeping up as well. VSCode, _I'm personally not a fan of it_ -- it's given me a lot of trouble for Java development in the past, and I don't plan on using it for bigger Java projects any time soon. However, as long as you can get the job done in whatever you're comfortable with you're free to use it. |
23 | 8 |
|
24 | 9 |
|
25 | | -## Imports |
26 | | -There's a specific order your imports should follow: |
27 | | -```java |
28 | | -import io.github.lucasstarsz.fastj.engine.*; |
29 | | -import io.github.lucasstarsz.fastj.math.*; |
30 | | -import io.github.lucasstarsz.fastj.graphics.*; |
31 | | - |
32 | | -import io.github.lucasstarsz.fastj.systems.*; |
33 | | - |
34 | | -import java.*; |
35 | | -import javax.*; |
| 10 | +## Spotless |
| 11 | +[diffplug/spotless](https://github.com/diffplug/spotless) handles all import styling, and a little bit of general code formatting as well. |
36 | 12 |
|
37 | | -import others |
38 | | - |
39 | | -import static others |
40 | | - |
41 | | -public class ... { |
42 | | -} |
43 | | -``` |
44 | | - |
45 | | -A bit excessive, but for me (the owner of the repo, lucasstarsz, hi) it provides the most optimal reading -- not that anyone else reads them. |
| 13 | +**Remember to run `gradlew spotlessApply` on your code**. On pull requests, the GitHub Action scripts will all check whether the code is formatted according to `spotless`' liking. If it is not formatted, the checks will fail. Please keep this in mind! |
46 | 14 |
|
47 | 15 |
|
48 | 16 | ## General Code Style |
49 | 17 | For the most part, you can follow along with this codebase using [Google's Java Style Guide][Style-Guide-Link]. It covers most of the bases, with exceptions as follows: |
50 | 18 |
|
| 19 | + |
51 | 20 | ### Column Limit |
52 | 21 | Other than JUnit test asserts, Markdown, and Git commits -- I don't care about the exact style of these in terms of this, Lines should hard-wrap at the **120-character** limit, and not at 100. |
53 | 22 |
|
| 23 | + |
54 | 24 | ### Block Indentation |
55 | 25 | Indentation must be **4 spaces**. Indentations for method chaining must be **8 spaces**. |
56 | | - |
| 26 | + |
| 27 | + |
57 | 28 | ### Wildcard Imports |
58 | 29 | Wildcard imports are only allowed if the file's import count from that specific package is more than 10, with the same situation being applied to static imports more than 7. |
59 | 30 |
|
| 31 | + |
60 | 32 | ### Annotations |
61 | 33 | For the sake of my own sanity, until further notice I will not allow the exception regarding single parameterless annotations for methods. However: |
62 | 34 | - Single parameterless annotations for a field are always welcome to be on the same line. |
63 | 35 | - Otherwise, annotations must always be on a line of its own (one annotation per line). |
64 | 36 |
|
| 37 | + |
65 | 38 | ### Constant Names |
66 | 39 | All constant values (`static final`, `enum`) should follow `PascalCase`, rather than `CONSTANT_CASE`. |
67 | 40 | - Furthermore, shallow constants (e.g. `static final Set<Integer>`) should _also_ use `PascalCase`. |
68 | 41 |
|
| 42 | + |
69 | 43 | ### Type Variable Names |
70 | 44 | I have no preference on how these are named. |
71 | 45 |
|
| 46 | + |
72 | 47 | ### Acronyms in Variable Names |
73 | 48 | So long as they are only used when it makes the most sense to (e.g. FPS, UPS, or GL in the context of OpenGL), they are preferred. If it is not something easily recognized by acronym, it should not be given one (e.g. FJGL -- FastJ Game Library). |
74 | 49 |
|
75 | 50 |
|
| 51 | +## Code Comments |
| 52 | +If the code calls for it, please do provide some. It may also be a sign that your code could otherwise be simplified 😛 |
| 53 | +- Comments, wither single or multi-block, should remain within 100 characters long. The rest should be on a new line. |
| 54 | +- If a comment is found to be unhelpful or otherwise redundant in a PR, the PR may not be allowed to merge until the usage of those comments is discussed thoroughly. |
| 55 | + |
| 56 | + |
76 | 57 | ## Documentation |
77 | 58 | Please see [Contributing Documentation][Contributing-Documentation]. |
78 | 59 |
|
| 60 | + |
| 61 | +## Logging |
| 62 | +FastJ uses [SimpleLogger]() as its supplementary logging library to `SLF4J`. As such, the `test` section contains a `simpleLogger.properties` file that can be edited -- but preferably not updated -- over time. |
| 63 | +- Use `Log.`, and not `FastJEngine.` in your logging -- each logging statement should specify which class it comes from. |
| 64 | +- Use message parameterization -- review [this section of SLF4J's documentation](https://www.slf4j.org/faq.html#logging_performance) for more details. |
| 65 | + |
| 66 | +An example of the expected logging scheme is provided below: |
| 67 | +```java |
| 68 | +Log.warn(MyClass, "message {}", formattedContent); |
| 69 | +``` |
| 70 | + |
| 71 | + |
79 | 72 | ## Unit Tests |
80 | | -Unit Tests are an integral part of the project. No part of the project should be left untested -- I am currently working hard to give this project as much unit testing as possible. |
| 73 | +Unit Tests are an essential part of the project's success. No part of the project should be left untested -- I am currently working hard to give this project as much unit testing as possible. |
81 | 74 |
|
82 | 75 | New code added to the repository should **always** be accompanied by unit testing. There is no exception to this -- PRs without unit tests for new methods added (of course, there are exceptions to this rule) will **not** be merged. |
83 | 76 |
|
| 77 | +FastJ makes use of [JUnit 5](https://junit.org/junit5/) for its unit testing purposes. If you're not directly familiar with this version of JUnit (as it has some key differences from its predecessor JUnit 4) please make sure you read through the JUnit guide before/while you write your unit tests. |
| 78 | +- [Webpage/Docs version of the guide](https://junit.org/junit5/docs/current/user-guide/) |
| 79 | +- [PDF version of the guide](https://junit.org/junit5/docs/current/user-guide/junit-user-guide-5.8.2.pdf) |
| 80 | + |
| 81 | +### Visibility |
| 82 | +- All unit test classes and test cases should have `package-private` visiblity. |
| 83 | +- All other components to the unit tests should be given visibility based on best judgement. |
| 84 | +- All packages in `unittest` that contain classes with test cases should be opened to `junit-platform-commons` in the `module-info.java` file, for example: |
| 85 | + ```java |
| 86 | + // inside module-info.java |
| 87 | + opens unittest.testcases.graphics to org.junit.platform.commons; |
| 88 | + ``` |
| 89 | + |
| 90 | + |
| 91 | +### Naming |
| 92 | +- Classes should contain test cases regarding the topic being tested against. |
| 93 | +- For checking normal assertions: |
| 94 | + ```java |
| 95 | + @Test |
| 96 | + void checkSomeThingAction<_withOtherRelatedInformation><_shouldPerformAction>() {} |
| 97 | + |
| 98 | + @Test |
| 99 | + void checkSomeThings_SpecificInformation() {} |
| 100 | + ``` |
| 101 | +- For exception-related assertions: |
| 102 | + ```java |
| 103 | + @Test |
| 104 | + void tryErroneousAction<_withInvalidOrErroneousParameters>_shouldThrowExceptionOrSomeOtherAction() {} |
| 105 | + ``` |
| 106 | +- For `BeforeAll` assumptions: |
| 107 | + ```java |
| 108 | + @BeforeAll |
| 109 | + public static void onlyRunIfSomeCondition() {} |
| 110 | + ``` |
| 111 | +Items in `<>` are optional. |
| 112 | + |
84 | 113 |
|
85 | 114 | [IntelliJ-Link]: https://www.jetbrains.com/idea/ "IntelliJ IDEA IDE" |
86 | 115 | [Eclipse-Link]: https://www.eclipse.org/downloads/ "Eclipse IDE" |
|
0 commit comments