You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developers/code-style.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ in `pom.xml` directly.
28
28
29
29
It is recommended to define version of library to separate property in `pom.xml`:
30
30
31
-
```
31
+
```xml
32
32
<project>
33
33
<properties>
34
34
<caffeine.version>2.6.2</caffeine.version>
@@ -48,7 +48,7 @@ It is recommended to define version of library to separate property in `pom.xml`
48
48
49
49
Do not use wildcard in imports because they hide what exactly is required by the class.
50
50
51
-
```
51
+
```java
52
52
// bad
53
53
importjava.util.*;
54
54
@@ -61,7 +61,7 @@ import java.util.Map;
61
61
62
62
Prefer to use `camelCase` naming convention for variables and methods.
63
63
64
-
```
64
+
```java
65
65
// bad
66
66
String account_id ="id";
67
67
@@ -71,7 +71,7 @@ String accountId = "id";
71
71
72
72
Name of variable should be self-explanatory:
73
73
74
-
```
74
+
```java
75
75
// bad
76
76
String s = resolveParamA();
77
77
@@ -83,7 +83,7 @@ This helps other developers flesh your code out better without additional questi
83
83
84
84
For `Map`s it is recommended to use `To` between key and value designation:
85
85
86
-
```
86
+
```java
87
87
// bad
88
88
Map<Imp, ExtImp> map = getData();
89
89
@@ -97,7 +97,7 @@ Make data transfer object(DTO) classes immutable with static constructor.
97
97
This can be achieved by using Lombok and `@Value(staticConstructor="of")`. When constructor uses multiple(more than 4) arguments, use builder instead(`@Builder`).
98
98
If dto must be modified somewhere, use builders annotation `toBuilder=true` parameter and rebuild instance by calling `toBuilder()` method.
99
99
100
-
```
100
+
```java
101
101
// bad
102
102
publicclassMyDto {
103
103
@@ -138,7 +138,7 @@ final MyDto updatedDto = myDto.toBuilder().value("newValue").build();
138
138
Although Java supports the `var` keyword at the time of writing this documentation, the maintainers have chosen not to utilize it within the PBS codebase.
139
139
Instead, write full variable type.
140
140
141
-
```
141
+
```java
142
142
// bad
143
143
finalvar result = getResult();
144
144
@@ -150,7 +150,7 @@ final Data result = getResult();
150
150
151
151
Enclosing parenthesis should be placed on expression end.
152
152
153
-
```
153
+
```java
154
154
// bad
155
155
methodCall(
156
156
long list of arguments
@@ -163,7 +163,7 @@ methodCall(
163
163
164
164
This also applies for nested expressions.
165
165
166
-
```
166
+
```java
167
167
// bad
168
168
methodCall(
169
169
nestedCall(
@@ -181,7 +181,7 @@ methodCall(
181
181
182
182
Please, place methods inside a class in call order.
183
183
184
-
```
184
+
```java
185
185
// bad
186
186
publicinterfaceTest {
187
187
@@ -249,7 +249,7 @@ Define interface first method, then all methods that it is calling, then second
249
249
Not strict, but methods with long parameters list, that cannot be placed on single line,
250
250
should add empty line before body definition.
251
251
252
-
```
252
+
```java
253
253
// bad
254
254
publicstatic void method(
255
255
parameters definitions) {
@@ -266,7 +266,7 @@ public static void method(
266
266
267
267
Use collection literals where it is possible to define and initialize collections.
268
268
269
-
```
269
+
```java
270
270
// bad
271
271
finalList<String> foo =newArrayList();
272
272
foo.add("foo");
@@ -278,7 +278,7 @@ final List<String> foo = List.of("foo", "bar");
278
278
279
279
Also, use special methods of Collections classfor empty or single-value one-line collection creation. This makes developer intention clear and code less error-prone.
Do not rely on operator precedence in boolean logic, use parenthesis instead. This will make code simpler and less error-prone.
337
337
338
-
```
338
+
```java
339
339
// bad
340
340
final boolean result = a && b || c;
341
341
@@ -347,7 +347,7 @@ final boolean result = (a && b) || c;
347
347
348
348
Try to avoid hard-readable multiple nested method calls:
349
349
350
-
```
350
+
```java
351
351
// bad
352
352
int resolvedValue = resolveValue(fetchExternalJson(url, httpClient), populateAdditionalKeys(mainKeys, keyResolver));
353
353
@@ -361,7 +361,7 @@ int resolvedValue = resolveValue(externalJson, additionalKeys);
361
361
362
362
Try not to retrieve same data more than once:
363
363
364
-
```
364
+
```java
365
365
// bad
366
366
if (getData() != null) {
367
367
finalData resolvedData = resolveData(getData());
@@ -380,7 +380,7 @@ if (data != null) {
380
380
381
381
If you're dealing with incoming data, please be sure to check if the nested object is not null before chaining.
382
382
383
-
```
383
+
```java
384
384
// bad
385
385
final ExtRequestTargeting targeting = bidRequest.getExt().getPrebid().getTargeting();
386
386
@@ -400,7 +400,7 @@ We are trying to get rid of long chains of null checks, which are described in s
400
400
401
401
Don't leave commented code (don't think about the future).
402
402
403
-
```
403
+
```java
404
404
// bad
405
405
// String iWillUseThisLater = "never";
406
406
```
@@ -426,7 +426,7 @@ The code should be covered over 90%.
426
426
427
427
The common way for writing tests has to comply with `given-when-then` style.
428
428
429
-
```
429
+
```java
430
430
// given
431
431
final BidRequest bidRequest = BidRequest.builder().id("").build();
432
432
@@ -451,7 +451,7 @@ The team decided to use name `target` for class instance under test.
451
451
452
452
Unit tests should be as granular as possible. Try to split unit tests into smaller ones until this is impossible to do.
453
453
454
-
```
454
+
```java
455
455
// bad
456
456
@Test
457
457
public void testFooBar() {
@@ -487,7 +487,7 @@ public void testBar() {
487
487
This also applies to cases where same method is tested with different arguments inside single unit test.
488
488
Note: This represents the replacement we have selected for parameterized testing.
489
489
490
-
```
490
+
```java
491
491
// bad
492
492
@Test
493
493
public void testFooFirstSecond() {
@@ -527,7 +527,7 @@ It is also recommended to structure test method names with this scheme:
527
527
name of method that is being tested, word `should`, what a method should return.
528
528
If a method should return something based on a certain condition, add word `when` and description of a condition.
529
529
530
-
```
530
+
```java
531
531
// bad
532
532
@Test
533
533
public void doSomethingTest() {
@@ -547,7 +547,7 @@ public void processDataShouldReturnResultWhenInputIsData() {
547
547
548
548
Place data used in test as close as possible to test code. This will make tests easier to read, review and understand.
549
549
550
-
```
550
+
```java
551
551
// bad
552
552
@Test
553
553
public void testFoo() {
@@ -576,7 +576,7 @@ This point also implies the next one.
576
576
Since we are trying to improve test simplicity and readability and place test data close to tests, we decided to avoid usage of top level constants where it is possible.
577
577
Instead, just inline constant values.
578
578
579
-
```
579
+
```java
580
580
// bad
581
581
public class TestClass {
582
582
@@ -609,7 +609,7 @@ public class TestClass {
609
609
610
610
Don't use real information in tests, like existing endpoint URLs, account IDs, etc.
0 commit comments