-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-style.html
474 lines (406 loc) · 16 KB
/
code-style.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Code-Style</title>
<style>
body {
background-color: rgba(0, 128, 0, 0);
margin-left: 200px;
}
h1 {
color: crimson;
text-align: center;
}
h2 {
color: #0f0f0f;
margin-top: 40px;
background-color: #eeeeee;
width: 80%;
}
div {
margin-top: 20px;
}
p {
font-family: verdana;
font-size: 14px;
}
a {
color: slateblue;
text-decoration: none;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-size: 14px;
}
a:hover {
color: deeppink;
text-decoration: underline;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 80%;
}
td,
th {
border: 1px solid #eeeeee;
text-align: left;
padding: 12px;
}
</style>
</head>
<body>
<h1>Code Style - Code Review</h1>
<div>
<ul style="list-style-type:none;">
<li><a href="#id0">DoD </a></li>
<li><a href="#id1">Sonar Rules</a></li>
<li><a href="#id2">Java Coding Standards</a></li>
<li><a href="#id3">Typescript (inc. VSCode API) Coding Standards</a></li>
<li><a href="#id4">Common Standards</a></li>
<li><a href="#id5">Code Review - Code of Conducts</a></li>
</ul>
</div>
<p>
Action: After each Code Style related technical discussions, or topics presented, below tables will be updated according to team-agreed action-points.
</p>
<h2 id="id0">DoD - Definition of Done </h2>
Check if all steps of DoD completed:
<a href="https://www.geeksforgeeks.org/coding-standards-and-guidelines/">Coding Standards</a>,
<a href="#">DoD in Jira/RTC/Rally</a>,
<a href="https://ci.eclipse.org/che4z/">Jenkins build</a>,
<a href="https://www.scrumguides.org/scrum-guide.html#artifact-transparency-done">DoD in Scrum</a>
<a href="https://github.com/marketplace/actions/assign-to-one-project">OneProject</a>
<h2 id="id1">Sonar Rules </h2>
<div>
<table>
<tr>
<td>
<b>Java Rules, .. </b>
</td>
<td>
<b>Typescript Rules </b>
</td>
<td>
More ..
</td>
</tr>
<tr>
<td>
<a href="https://sonarcloud.io/organizations/eclipse/rules?languages=java">Sonarcloud-Java</a>,
<a href="#">Sonarqube-Java</a>,
<a href="https://sonarcloud.io/dashboard?id=eclipse_che-che4z-lsp-for-cobol">sonarcloud-che4z-lsp-for-cobol</a>,
<a href="https://sonarcloud.io/organizations/eclipse/rules?languages=cobol">Cobol</a>, <br />
<a href="https://github.com/eclipse/che-che4z-lsp-for-cobol/wiki/Code-Style-Guide">eclipse/che-che4z-lsp-for-cobol - code style</a>
</td>
<td>
<a href="https://sonarcloud.io/organizations/eclipse/rules?languages=ts">Sonarcloud-TS</a>,
<a href="#">Sonarqube-TS</a>
</td>
<td>
<a href="https://rules.sonarsource.com/ " target="_blank">Sonar Rules</a>,
<a href=" https://www.sonarqube.org/">Sonarqube</a>,
<a href="https://docs.sonarqube.org/latest/analysis/languages/java/">docs</a>,
<a href="https://sonarcloud.io/">sonarcloud</a>,
<a href="https://owasp.org/www-pdf-archive/OWASP_Top_10-2017_%28en%29.pdf.pdf">OWASP</a>
</td>
</tr>
</table>
</div>
<h2 id="id2">Java Coding Standards</h2>
<p>
To build robust Java enterprise application, it is important for development teams to adopt proven design
techniques and follow good coding standards.
<br />
Official: <a href="https://www.oracle.com/technetwork/java/codeconvtoc-136057.html">Code Conventions for the
Java</a>,
<a href="https://en.wikibooks.org/wiki/Java_Programming/Coding_conventions">wiki</a>, Google's coding standards
for source code in the Java™ Programming Language:
<a href="https://google.github.io/styleguide/javaguide.html#s4.6.2-horizontal-whitespace">Google Java Style
Guide</a>
</p>
<p>
As a development team we follow these conventions, and also improve it according to project need by defining
some agreed coding styles in below table.
</p>
<div>
<table>
<tr>
<td>
<b>Argument</b>
</td>
<td>
<b>Example</b>
</td>
<td>
<b>Reason</b>
</td>
<td>
<b>Comment</b>
</td>
</tr>
<tr>
<td>
Using Collection Factory methods
</td>
<td>
<code>
List<String> expected = new ArrayList<>();<br/>
expected.add(VAR1);<br/>
expected.add(VAR2);<br/>
//becomes<br/>
List<String> expected = List.of(VAR1, VAR2);<br/>
//or if Arrays.asList usage is immutable <br />
Arrays.asList(new CobolText("CPYBK1", COPYBOOK1), new CobolText("CPYBK2", COPYBOOK2))<br/>
//better use List.of <br/>
List.of(new CobolText("CPYBK1", COPYBOOK1), new CobolText("CPYBK2", COPYBOOK2))</code>
</td>
<td>
unmodifiable, otherwise UnsupportedOperationException, also allows List.copyOf(list);
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Guava Lists.newarraysList
</td>
<td>
<code>List<String> lines = new ArrayList<>(); (//or if Arrays.asList usage is mutable)<br/>
lines.add(firstLine);<br/>
lines.add(""); </br/>
//becomes<br/>
List<String> lines = Lists.newArrayList(firstLine, "");</code>
</td>
<td>
Allows add, remove,Iterables.removeIf. Also shorter, cleaner and still mutable.
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Benefit of Predicate.not/or.., Optionals
</td>
<td>
</td>
<td>
Reusable code and null-safe code
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Using Local Var
</td>
<td>
<code> long genDt = Instant.now().minus(1, ChronoUnit.MILLIS).toEpochMilli();<br/>
CopybookStorable storableCpy = new CopybookStorable("REMOVE", "URI", "DUMMY CONTENT");<br/>
//becomes<br/>
var genDt = Instant.now().minus(1, ChronoUnit.MILLIS).toEpochMilli();<br/>
var storableCpy = new CopybookStorable("REMOVE", "URI", "DUMMY CONTENT");</code>
</td>
<td>
shorter, and should not be used for long Streams piped chains
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Using Unicode-aware new String methods like: isBlank(), strip(), <br/>
stripLeading() , stripTrailing() .. instead of isEmpty(), trim(), ..
</td>
<td>
<code> var res = " "; //"\n\t\u2005"<br/>
//return false
assertTrue(res.isEmpty());<br/>
//works correctly<br/>
assertTrue(res.isBlank());<br/></code>
</td>
<td>
Unicode-aware based on Character::isWhitespace, not like before on \u0020
</td>
<td>
17.6.2020
</td>
</tr>
<tr>
<td>
Using Hamcrest matchers assertThat instead of JUnit assert* methods
</td>
<td>
<code> assertEquals(1, processed.getErrors().seize());<br/>
//prefer<br/>
assertThat(processed.getErrors(), hasSize(1));<br/></code>
</td>
<td>
more readable and promotes bdd style tests
</td>
<td>
</td>
</tr>
</table>
</div>
<h2 id="id3">Typescript (inc. VSCode API) Coding Standards</h2>
<p>
Starting with ECMAScript 2015, a.k.a ECMAScript 6, JavaScript programmers will be able to build their
applications using this object-oriented class-based approach. <br />
In TypeScript, developers are allowed to use these techniques now, and compile them down to JavaScript that
works across all major browsers and platforms, without having <br />
to wait for the next version of JavaScript.
Official: <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html">Typescript</a>, and
API reference documentation for - <a href="https://nodejs.org/api/fs.html"> Node.js - API</a>, Google JavaScript: <a href="https://google.github.io/styleguide/jsguide.html">Style Guide</a> <br />
<b>VS Code API</b> is a set of JavaScript APIs that you can invoke in your <b>VS Code extension</b> - <a
href="https://code.visualstudio.com/api/references/vscode-api">VS Code API</a>,
<a href="https://github.com/Microsoft/vscode/wiki/Coding-Guidelines">Coding Guidelines</a>
</p>
<div>
<table>
<tr>
<td>
<b>Argument</b>
</td>
<td>
<b>Example</b>
</td>
<td>
<b>Reason</b>
</td>
<td>
<b>Comment</b>
</td>
</tr>
<tr>
<td>
Assigning TypeScript injections<br /> through parameters
</td>
<td>
<code>
// Don't do this<br />
class User {<br />
private firstName: string;<br />
private lastName: string;<br />
constructor(firstName: string, lastName: string) {<br />
this.firstName = firstName;<br />
this.lastName = lastName;<br />
}<br />
}<br />
<br />
//Instead do this<br />
class User {<br />
constructor(private firstName: string, private lastName: string) {<br />
}<br />
}
</code>
</td>
<td>
Reduces duplicate work<br />
Cleans up injections
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Using TypeScript Destructions </td>
<td>
<code>
//Instead of this<br />
let input = [1, 2];<br />
let first = input[0];<br />
let second = input[1];<br />
}<br />
}
<br />
//Use destructions <br />
let input = [1, 2];<br />
let [first, second] = input;<br />
}<br />
}
</code>
</td>
<td>
More convenient, especially handy using with remaining items in a list using the syntax ... REST
</td>
<td>
17.6.2020 ?
</td>
</tr>
</table>
</div>
<h2 id="id4">Common Standards</h2>
<div>
<table>
<tr>
<td>
<b>Argument</b>
</td>
<td>
<b>Example</b>
</td>
<td>
<b>Reason</b>
</td>
<td>
<b>Comment</b>
</td>
</tr>
<tr>
<td>
JSON comments
</td>
<td>
<code>
"search.exclude": {<br />
"out": true // false to include "out" folder in search results<br />
}<br /><br />
//should be <br />
"search.exclude": {<br />
"out": true <br />
}
</code>
</td>
<td>
Even though valid. According to JSON spec,
comments are not allowed inside the structure.
</td>
<td>
17.6.2020 ?
</td>
</tr>
<tr>
<td>
Git Merge or Rebage
</td>
<td>
When to apply Rebase or Merge
</td>
<td>
Regarding to multi-branching, merge conflicts better to apply agreed pattern.
</td>
<td>
1.6.2020
</td>
</tr>
</table>
</div>
<h2 id="id5">Code Review - Code of Conducts</h2>
<ul style="list-style-type:none;">
<li>Provide code quality together - Team Work</li>
<li>Learn and improve together</li>
<li>Code Review is a discussion process to reach a consensus.</li>
<li>Provide best practices, APIs, links to resources i.e wiki, stack overflow, etc. </li>
<li>Collaborate with teammate/s to move Code Review forward via. g-chat, or g-meet, etc.</li>
<li>Provide constructive comments, "This will improve ..." or "According to spec... " or "Java Coding Standards
...", "Sonar findings" etc. </li>
<li>Collaborate with asking questions and provide answers to understand each-other</li>
<li>Review big PR/s with pause breaks which helps you to recharge/rehydrate, and to concentrate more</li>
</ul>
</body>
</html>