Skip to content

Commit 516236c

Browse files
qodo-code-review[bot]soul2zimate
authored andcommitted
Generated best practices file
1 parent c442161 commit 516236c

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

best_practices.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
<b>Pattern 1: Require explicit runtime configuration for backend/service endpoints and fail fast when required environment variables or CLI arguments are missing, rather than shipping defaults or vendor-specific endpoints. Ensure docs and examples stay provider-agnostic and do not include internal/third-party service URLs.
3+
</b>
4+
5+
Example code before:
6+
```
7+
private static final String DEFAULT_ENDPOINT = "https://vendor.example.com";
8+
9+
String endpoint = Environment.get("BACKEND_URL", DEFAULT_ENDPOINT);
10+
// continues with default even when not configured
11+
```
12+
13+
Example code after:
14+
```
15+
String endpoint = Environment.get("BACKEND_URL");
16+
if (endpoint == null || endpoint.trim().isEmpty()) {
17+
throw new IllegalStateException(
18+
"Backend URL not configured. Please set BACKEND_URL.");
19+
}
20+
endpoint = endpoint.trim();
21+
```
22+
23+
<details><summary>Examples for relevant past discussions:</summary>
24+
25+
- https://github.com/guacsec/trustify-da-java-client/pull/211#discussion_r2536810895
26+
- https://github.com/guacsec/trustify-da-java-client/pull/211#discussion_r2537678862
27+
</details>
28+
29+
30+
___
31+
32+
<b>Pattern 2: When introducing a new configuration key/behavior that supersedes a legacy one, enforce deterministic precedence (new overrides old) and migrate examples/docs to primarily show the new key; only mention the legacy key as backwards compatibility. In code, centralize these keys as constants and implement the precedence logic once.
33+
</b>
34+
35+
Example code before:
36+
```
37+
// scattered literals and unclear precedence
38+
var node = json.get("legacyIgnore");
39+
if (node == null || node.isEmpty()) {
40+
node = json.get("newIgnore");
41+
}
42+
```
43+
44+
Example code after:
45+
```
46+
// constants + explicit precedence: new wins
47+
var node = json.get(IGNORE_NEW);
48+
if (node == null || node.isEmpty()) {
49+
node = json.get(IGNORE_LEGACY);
50+
}
51+
if (node == null || node.isEmpty()) return Set.of();
52+
```
53+
54+
<details><summary>Examples for relevant past discussions:</summary>
55+
56+
- https://github.com/guacsec/trustify-da-java-client/pull/205#discussion_r2526224893
57+
- https://github.com/guacsec/trustify-da-java-client/pull/205#discussion_r2526228973
58+
- https://github.com/guacsec/trustify-da-java-client/pull/205#discussion_r2526232347
59+
- https://github.com/guacsec/trustify-da-java-client/pull/205#discussion_r2526242594
60+
- https://github.com/guacsec/trustify-da-java-client/pull/205#discussion_r2526258368
61+
</details>
62+
63+
64+
___
65+
66+
<b>Pattern 3: Prefer failing with exceptions (and include stderr/context) over merely logging when an external tool/process invocation or required precondition fails, so callers get actionable failures. Use logging for diagnostics, not as a substitute for error handling.
67+
</b>
68+
69+
Example code before:
70+
```
71+
String out = Operations.run(cmd);
72+
if (out == null) {
73+
LOG.warning("Tool failed, continuing");
74+
return "";
75+
}
76+
```
77+
78+
Example code after:
79+
```
80+
ProcessResult r = Operations.runWithResult(cmd);
81+
if (r.exitCode() != 0) {
82+
throw new IOException("Tool failed: " + r.stderr());
83+
}
84+
return r.stdout();
85+
```
86+
87+
<details><summary>Examples for relevant past discussions:</summary>
88+
89+
- https://github.com/guacsec/trustify-da-java-client/pull/167#discussion_r2228021393
90+
</details>
91+
92+
93+
___
94+
95+
<b>Pattern 4: Keep documentation and code comments minimal, accurate, and non-redundant: avoid repeating the same environment-variable setup in every example, remove outdated/irrelevant comments, and ensure parameter names match their Javadoc. Prefer a single “export once” step and then concise usage examples.
96+
</b>
97+
98+
Example code before:
99+
```
100+
# Example 1
101+
export BACKEND_URL=http://localhost:8080
102+
tool cmd1
103+
104+
# Example 2
105+
export BACKEND_URL=http://localhost:8080
106+
tool cmd2
107+
```
108+
109+
Example code after:
110+
```
111+
# Configure once
112+
export BACKEND_URL=http://localhost:8080
113+
114+
# Examples
115+
tool cmd1
116+
tool cmd2
117+
```
118+
119+
<details><summary>Examples for relevant past discussions:</summary>
120+
121+
- https://github.com/guacsec/trustify-da-java-client/pull/211#discussion_r2537683064
122+
- https://github.com/guacsec/trustify-da-java-client/pull/211#discussion_r2537686339
123+
- https://github.com/guacsec/trustify-da-java-client/pull/127#discussion_r2047246406
124+
- https://github.com/guacsec/trustify-da-java-client/pull/114#discussion_r2031484262
125+
</details>
126+
127+
128+
___

0 commit comments

Comments
 (0)