-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1422 lines (1120 loc) · 42.6 KB
/
index.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Take-Home Messages from Adding Code Quality Measures to GRASS GIS</title>
<meta name="description" content="Take-Home Messages from Adding Code Quality Measures to GRASS GIS - slides for FOSS4G 2022, August 25">
<meta name="author" content="Vaclav Petras">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="css/theme/osgeo.css" id="theme">
<link rel="stylesheet" href="css/nouislider.min.css" id="slide">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css" id="highlight-theme">
<!-- For chalkboard plugin -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!-- <link href="https://fonts.googleapis.com/css?family=Miriam+Libre" rel="stylesheet">-->
<style>
/* miriam-libre-regular - latin */
@font-face {
font-family: 'Miriam Libre';
font-style: normal;
font-weight: 400;
src: url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.eot'); /* IE9 Compat Modes */
src: local('Miriam Libre'), local('MiriamLibre-Regular'),
url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.woff') format('woff'), /* Modern Browsers */
url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('lib/font/miriam-libre/miriam-libre-v1-latin-regular.svg#MiriamLibre') format('svg'); /* Legacy iOS */
}
/* miriam-libre-700 - latin */
@font-face {
font-family: 'Miriam Libre';
font-style: normal;
font-weight: 700;
src: url('lib/font/miriam-libre/miriam-libre-v1-latin-700.eot'); /* IE9 Compat Modes */
src: local('Miriam Libre Bold'), local('MiriamLibre-Bold'),
url('lib/font/miriam-libre/miriam-libre-v1-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('lib/font/miriam-libre/miriam-libre-v1-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
url('lib/font/miriam-libre/miriam-libre-v1-latin-700.woff') format('woff'), /* Modern Browsers */
url('lib/font/miriam-libre/miriam-libre-v1-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
url('lib/font/miriam-libre/miriam-libre-v1-latin-700.svg#MiriamLibre') format('svg'); /* Legacy iOS */
}
/* sintony-regular - latin */
@font-face {
font-family: 'Sintony';
font-style: normal;
font-weight: 400;
src: url('lib/font/sintony/sintony-v4-latin-regular.eot'); /* IE9 Compat Modes */
src: local('Sintony'),
url('lib/font/sintony/sintony-v4-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('lib/font/sintony/sintony-v4-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('lib/font/sintony/sintony-v4-latin-regular.woff') format('woff'), /* Modern Browsers */
url('lib/font/sintony/sintony-v4-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('lib/font/sintony/sintony-v4-latin-regular.svg#Sintony') format('svg'); /* Legacy iOS */
}
/* sintony-700 - latin */
@font-face {
font-family: 'Sintony';
font-style: normal;
font-weight: 700;
src: url('lib/font/sintony/sintony-v4-latin-700.eot'); /* IE9 Compat Modes */
src: local('Sintony Bold'), local('Sintony-Bold'),
url('lib/font/sintony/sintony-v4-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('lib/font/sintony/sintony-v4-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
url('lib/font/sintony/sintony-v4-latin-700.woff') format('woff'), /* Modern Browsers */
url('lib/font/sintony/sintony-v4-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
url('lib/font/sintony/sintony-v4-latin-700.svg#Sintony') format('svg'); /* Legacy iOS */
}
.reveal li > ul {
font-size: 85%;
line-height: 110%;
}
.reveal small {
display: inline-block;
font-size: smaller;
line-height: 1.2em;
vertical-align: baseline;
margin: 0.1em; }
.reveal small * {
vertical-align: baseline; }
.reveal .credit {
font-size: small;
color: gray;
margin: 0.1em;
}
.reveal .right, .reveal .textimg > img, .reveal .textimg > video, .reveal .textimg > iframe, .reveal .imgtext > p, .reveal .imgtext > ul, .reveal .imgtext > ol, .reveal .imgtext > div {
float: right;
text-align: left;
max-width: 47%;
}
.reveal .left, .reveal .imgtext > img, .reveal .imgtext > video, .reveal .imgtext > iframe, .reveal .textimg > p, .reveal .textimg > ul, .reveal .textimg > ol, .reveal .textimg > div {
float: left;
text-align: left;
max-width: 47%;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<!--
The message is not surprising: You should quality check your code, too, even if you are writing a small script for your own needs!
However, maybe you wondered if all the warning messages are relevant to you or got discouraged after getting a flood of messages
from tools like Pylint. Perhaps you were even annoyed by it. This talk will help you get motivated and get started
and how to automate that with continuous integration tools such as GitHub Actions.
In this talk, I will share my experience with adding various code and non-code checks to GRASS GIS which is primarily
written in C, C++, and Python. Checking a mixed code base with over 30 years of development is not easy, but not impossible.
The talk will cover code quality measures in GRASS GIS such as tests, Pylint, Black, GCC, CodeQL, and Super-Linter
and how this compares to my experience with new and small organizational repositories.
-->
<section>
<h1>Take-Home Messages from Adding Code Quality Measures to GRASS GIS</h1>
<p style="margin-top: 0.5em">
<a href="http://wenzeslaus.github.io/" style="font-weight: bold">
Vaclav (Vashek) Petras
</a>
</p>
<p class="title-foot">
<a href="http://geospatial.ncsu.edu/geoforall/" title="NCSU GeoForAll Lab">NCSU GeoForAll Lab</a>
at the
<a href="http://geospatial.ncsu.edu/" title="NCSU Center for Geospatial Analytics">Center for Geospatial Analytics</a>
<br>
<a href="http://www.ncsu.edu/" title="North Carolina State University">North Carolina State University</a>
</p>
<img src="img/grass_gis.svg" class="stretch" alt="GRASS GIS logo">
<p><small>FOSS4G Firenze, August 25, 2022</small></p>
<p>
<a href="https://wenzeslaus.github.io/code-quality-measures-foss4g-2022/">wenzeslaus.github.io/code-quality-measures-foss4g-2022</a>
</section>
<section class="textimg">
<h2>Vaclav (Vashek) Petras</h2>
<div>
Geospatial Research Software Engineer at North Carolina State University
<p>
<img src="img/ncsu.svg" alt="North Carolina State University">
<img src="img/ncsu_cga.svg" alt="Center for Geospatial Analytics at NC State">
</p>
<p><small>
Research software engineering as a service, Tangible Landscape support, open source development, skill-transfer at
<a href="https://cnr.ncsu.edu/geospatial/engage/service-center/">geospatial.ncsu.edu</a>
</small></p>
</div>
<img src="img/cli_tangible.png">
</section>
<section>
<h2>Credit to the Community</h2>
<p>
Large contributions by:
Nicklas Larsson, Anna Petrasova, Carmen Tawalika, Loïc Bartoletti, Vaclav Petras
</p>
<img src="img/osgeo_codesprint_2018.jpg" class="stretch">
</section>
<section>
<h2>General Features</h2>
<ul>
<li>
Command line tools:
<b>500+</b> <a href="https://grass.osgeo.org/grass82/manuals/full_index.html">in core</a>,
<b>400+</b> <a href="https://grass.osgeo.org/grass82/manuals/addons/">addons</a>
<!-- (C, C++, Python) -->
</li>
<li>Dynamic libraries (C, C++): <b>50+</b></li>
<li>Python (sub-)packages (<em> grass.* </em>): <b>10+</b></li>
<li>Interfaces (native): graphical, command line, Python, C</li>
<li>Innovation with Stability & All-in-one Software Suite
<small>mission: <em>Bringing advanced geospatial technologies to the world</em></small>
</ul>
<img src="img/github_languages_combined.png" class="stretch">
</section>
<section>
<h2>Development Centered Around GitHub</h2>
<ul>
<li>Git</li>
<li>PRs</li>
<li>Issues</li>
<li>
GitHub Actions <small>(A lot of free CI time since 2018.)</small>
</li>
</ul>
<br>
<img src="img/laptops.jpg" class="stretch">
</section>
<section>
<h2>Python Tools Used in GRASS GIS</h2>
<ul>
<li>Python code formatted by Black.</li>
<li>Checked against Flake8.</li>
<li>Some code checked with Pylint.</li>
</ul>
<img src="img/code_in_vscodium.png" class="stretch">
</section>
<section>
<h2>C and C++ Tools Used in GRASS GIS</h2>
<ul>
<li>GCC, Clang <small>(locally)</small>, Coverity Scan <small>(mostly in the past)</small></li>
<li>Many GCC and Clang warnings fixed <small>for 8.0 and 8.2</small>.</li>
<li>Compiler warning compliance not yet enforced.</li>
<li>
GCC runs in CI with GNU C 99-17 and C++ 11-17.
<small>Checks mostly C++ language variations.</small>
</li>
</ul>
<img src="img/code_in_qtcreator.png" class="stretch">
</section>
<section>
<h2>General Tools Used in GRASS GIS</h2>
<ul>
<li>CodeQL checks for Python, C, and C++ enabled.</li>
<li>
Super-Linter checks for JSON, Perl, Powershell, XML, and YAML.
<small>Wanted: Bash, CSS, Docker, JavaScript, Markdown, HTML, MegaLinter</small>
</li>
<li>
Spellcheck scripts are in the <code>utils</code> directory <small>(to be used locally)</small>.
<small>Wanted: CSpell (possibly through MegaLinter)</small>
</li>
</ul>
<img src="img/markdown_in_gedit.png" class="stretch">
</section>
<section>
<h2>Statistics for GRASS GIS</h2>
<table>
<thead>
<tr>
<th></th>
<th>7.8.0</th>
<th>main branch</th>
</tr>
</thead>
<tbody>
<tr>
<td>PEP 8 formatting</td>
<td>25518</td>
<td>0*</td>
</tr>
<tr>
<td>Flake8</td>
<td>10590</td>
<td>3018**</td>
</tr>
<tr>
<td>GCC -Wall -Wextra</td>
<td>1200</td>
<td>959***</td>
</tr>
</tbody>
</table>
<small>
<p>*Assuming Black compliance equals PEP 8 compliance.</p>
<p>** Flake8 issues remaining: comments, start imports, unused variables, invalid escape sequences.</p>
<p>*** GCC critical issues fixed: dangling-else, discarded-qualifiers, format, logical-op, parentheses, pointers, restrict, tautological-compare, uninitialized.</p>
</small>
<!--
Flake8 now 3018, before 10590, 36108 including formatting
Flake8 now: comments, start imports, unused, invalid escape sequence
GCC -Wall -Wextra
present: unused, sign-compare, shadow, implicit-fallthrough, uninitialized, builtin-declaration-mismatch, type-limits
fixed: dangling-else, discarded-qualifiers, format, logical-op, parentheses, pointers, restrict, tautological-compare, uninitialized
-->
<img src="img/grass_logo_development.png" alt="GRASS GIS logo" class="stretch">
</section>
<section>
<h2>Work In Progress in GRASS GIS</h2>
<ul>
<li>
Pylint
<ul>
<li>
Runs for:
<ul>
<li>grass.jupyter & grass.benchmark</li>
<li>parts of gui/wxpython</li>
<li>all other files except gunittest's testsuite directories</li>
</ul>
</li>
<li>Different configuration for each group</li>
</ul>
</li>
<li>
CodeQL
<ul>
<li>
C and C++: 217 issues
<ul>
<li>Some are false positives for security, but show real issues.</li>
<li>Hard to communicate with contributors, although present in forks.</li>
<li>Cppcheck may work well as an alternative which can run locally.</li>
</ul>
</li>
<li>
Python: 2 issues
<ul>
<li>Bandit may be a better fit for Python and may find more, but will require a lot of configuration.</li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Two Linting Tool Examples</h2>
</section>
<section>
<h2>Python: Black</h2>
<ul>
<li>Unified Python formatting</li>
<li>Simplest to configure, apply, enforce</li>
<li>PEP 8 formatting compliance</li>
<li>Developed with "<code>git diff</code>" in mind</li>
</ul>
<p>
Apply formatting to all code:
<pre><code data-trim class="no-highlight">
black .
</code></pre>
Check in CI:
<pre><code data-trim class="no-highlight">
black --check .
</code></pre>
</section>
<section>
<h2>C & C++: valgrind</h2>
<ul>
<li>Memcheck is the default tool</li>
<li>Check memory usage of a program</li>
<li>Detects segmentation faults, leaked memory, …</li>
<li>Runs the program</li>
</ul>
<p>
In a GRASS session:
<pre><code data-trim class="no-highlight">
valgrind --leak-check=yes r.stats.quantile base=zipcodes cover=elevation quantiles=3 -p
valgrind --track-origins=yes --redzone-size=2048 d.legend soil_loss
</code></pre>
Using <code>--exec</code>:
<pre><code data-trim class="no-highlight">
grass --tmp-mapset ~/data/nc_spm/ --exec valgrind r.stats.quantile base=zipcodes cover=elevation quantiles=3 -p
</code></pre>
</section>
<section>
<h2>Benefits</h2>
</section>
<section>
<h2>Automated Formatting Is Easier</h2>
<ul>
<li>
Manual formatting according to a standard is hard or impossible,
while automatic formatting is easy.
<ul>
<!--<li>Using a command, editor configuration, GitHub Action, …</li>-->
<li>But: Should really be done using the tool.</li>
<!--<li>But: Auto-formatting in PRs confuses contributors</li>-->
</ul>
</li>
<li>
No need to discuss style with every change.
<ul>
<li>...or at least formatting is a separate discussion.</li>
<!--<li>…after the configuration has been created</li>-->
<!--<li>Separates the formatting discussion from specific code contributions</li>-->
</ul>
</li>
</ul>
<br>
<img src="img/prague_isprs_sprint_cafe_discussion.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Another endless discussion about code formatting style</small>
</section>
<section>
<h2>Code Checks Ensure Consistent Quality</h2>
<ul>
<li>
Common code quality level, defined, enforced.
<ul>
<li>Simple rule: <em>If the tools flags it, it needs to be fixed.</em></li>
</ul>
</li>
<li>
No need to check basic coding issues in PR reviews.
<ul>
<li>Reviewers focus on functionality and project-specific issues.</li>
<li>Reviews are hard and cost time, make them simpler!</li>
</ul>
</li>
</ul>
<img src="img/sprint_prague_2019.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Czechs happy after reviewing their code</small>
</section>
<section>
<h2>Checks Run On All Code</h2>
<ul>
<li>Manual testing is always incomplete.</li>
<li>Tests need to be written for specific parts of code.</li>
<li>
Linting has 100% coverage.
<ul>
<li>if configured that way</li>
<li>often with default settings</li>
<li>includes old and forgotten helper scripts</li>
</ul>
</li>
</ul>
<br>
<img src="img/sprint_boston.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Czechs looking into their code <small>(photo credit: Jody Garnett)</small></small>
</section>
<section>
<h2>Even Unrelated Warnings Expose Bugs</h2>
Code:
<pre><code data-trim>
gs.fatal(_("File does not exist: {name}".format(name=filename)))
</code></pre>
Pylint reports:
<pre><code data-trim class="no-highlight">
Formatting a regular string which could be a f-string (consider-using-f-string)
</code></pre>
<p>
Analysis:
<ul>
<li>
Looks like useless warning about not using the latest f-string syntax.
</li>
<li>
Draws attention to a line where a translate function
named <code>_</code> (underscore) is used.
</li>
<li>
The <em>format</em> function is called on the string,
but it should be called on the result of the translation function.
</li>
</ul>
</p>
Fixed code:
<pre><code data-trim class="python language-python">
gs.fatal(_("File does not exist: {name}").format(name=filename))
</code></pre>
</section>
<section>
<h2>Introducing Linters to a Project</h2>
</section>
<section>
<h2>Start Early</h2>
<p>
It is much easier start right at the beginning, than later on.
</p>
<p>
Even for small projects!
</p>
<p><small>It was hard to get started in GRASS GIS, but it is hard even for projects which are couple years old.</small></p>
<p style="font-size: 500%;">Now!</p>
<p>… but better late than never and certainly possible.</p>
<aside class="notes">
Why they just didn't use GitHub Actions from the beginning? …or something like that?
Initial release of CVS 1990, of Subversion (SVN) 2000, of Git 2005, of GitHub 2008, of GitHub Actions 2018 of GRASS GIS 1983.
</aside>
</section>
<section>
<h2>Enforce the Standards in CI</h2>
<ul>
<li>Don't rely on contributors running the checks locally.</li>
<li>With many checks, you can't even ask for that.</li>
<li>But: Have a way to run the checks locally.</li>
</ul>
<br>
<img src="img/prague_isprs_sprint_box.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Coding in a protective box</small>
</section>
<section>
<h2>Consider Warnings To Be Errors</h2>
<ul>
<li>Bad practice warning is useless if it is not enforced.</li>
<li>Some tools warn, but don't report that as a failure.</li>
<!--<li>Plain warnings are for good for transitional period.</li>-->
</ul>
<p><small>
Example for GCC and Clang:
</small></p>
<pre><code data-trim class="no-highlight">
gcc -Wall -Werror ...
</code></pre>
<img src="img/prague_isprs_sprint_cafe.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Minimize errors from spilled beer. You have been warned.</small>
</section>
<section>
<h2>Tips and Tricks</h2>
</section>
<section>
<h2>Be Specific in Excluding and Ignoring</h2>
Exclude only specific files or specific checks for specific files.
<p><small>
Flake8 can ignore warnings per file or directory:
</small></p>
<pre><code data-trim class="no-highlight">
per-file-ignores =
lib/init/grass.py: E501, E722, F821, F841, W605
gui/wxpython/vnet/*: F841, E501
</code></pre>
<p><small>
Warnings can be easily enabled again later from a single place.
</small></p>
<img src="img/meetup_fishbowl.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Be transparent in what is ignored</small>
</section>
<section>
<h2>Minimize Where Warning is Ignored</h2>
Disable only a specific warning for a specific directory, file, or line.
<p>
Yes — only one line:
<pre><code data-trim class="python language-python">
apple._refresh_core() # pylint: disable=protected-access
</code></pre>
No — everything after the line:
<pre><code data-trim class="python language-python">
# pylint: disable=protected-access
apple._refresh_core()
</code></pre>
Also: Line ignores and in-file ignores are best for ignores which are there to stay, i.e., the code just has to be that way or the warning does not apply
(e.g., access to private or protected methods in tests).
</section>
<section>
<h2>Refine Ignores</h2>
Continue improving your configuration and make it specific to your project.
<p>
Code:
<pre><code data-trim class="python language-python">
gs.fatal(_("File does not exist: {name}").format(name=filename))
</code></pre>
Original error from Pylint:
<pre><code data-trim class="no-highlight">
Undefined variable '_' (undefined-variable)
</code></pre>
Quick fix for Pylint by disabling the reported message:
<pre><code data-trim class="no-highlight">
disable=undefined-variable
</code></pre>
Full fix for Pylint by telling it about our code:
<pre><code data-trim class="no-highlight">
additional-builtins=_
</code></pre>
</section>
<section>
<h2>Explain Why You Ignore Warnings</h2>
<p>
For permanent ignores, include explanation.
</p>
<p>
<small>
Example: Pylint disable in a theoretical GUI application:
</small>
<pre><code data-trim class="python language-python">
# Always show an error message window even when the code is broken.
# This avoids tracebacks appearing without context.
except Exception as error: # pylint: disable=broad-except
show_error_window(error)
</code></pre>
<img src="img/prague_isprs_sprint_ctu_box_closeup.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Developers thinking hard what the code means</small>
<aside class="notes">
For all ignores in files and others which are meant to be permanent,
include explanation for why it is that way.
<p>
Later on, it will be clear, if the warning should be enabled or not.
</aside>
</section>
<section>
<h2>Contribute Time</h2>
<ul>
<li>
Fix the code.
<ul>
<li>Great learning experience: small and independent issues.</li>
<!-- with both general and GRASS-specific take-home messages-->
<li>
Submit a good PR:
<ul>
<li>Separate unrelated fixes into multiple PRs for easier review.</li>
<!--
<li>Separate fixes into PRs for easier review.</li>
<li>Group fixes into PRs (by error id or component).</li>--> <!--to avoid many similar PRs-->
<!--<li>Don't assume all errors just need to be ignored (leave it as is if needed).</li>-->
<li>Remove ignores from configuration.</li>
</ul>
</li>
<li>Join <em>Hour with the developer</em> at the Community Sprint.</li>
</ul>
</li>
<li>
Do another task to free someone's time for coding.
</li>
</ul>
<br>
<img src="img/sprint_boston_2017_tshirts.jpg" class="stretch">
<br>
<small style="font-size: 50%;">Feeling great after contributing to GRASS GIS</small>
</section>
<section>
<h2>Contribute Money</h2>
<ul>
<li>
Pay for fixing the code.
<ul>
<li><a href="https://opencollective.com/grass">opencollective.com/grass</a> → GRASS GIS Mini Grants, …</li>
<li>Pay a developer or company (we are here, talk to us).</li>
<li>Ask your employer to donate your or your colleague's time.</li>
</ul>
</li>
</ul>
<p style="font-size: 500%;">$</p>
</section>
<section>
<img src="img/grass_gis.svg" alt="GRASS GIS logo" class="stretch">
<p>
<a href="https://github.com/OSGeo/grass/"><small>Contribute:</small> github.com/OSGeo/grass</a>
</p>
<p>
<small>Get support from NC State University:</small> vpetras@ncsu.edu
</p>
<p>
<a href="https://twitter.com/vaclavpetras/"><small>Twitter:</small> vaclavpetras</a>
<br>
<a href="https://www.linkedin.com/in/vaclav-petras-a24a1b114/"><small>LinkedIn:</small> Vaclav Petras</a>
</p>
<p>
<a href="https://wenzeslaus.github.io/code-quality-measures-foss4g-2022/">wenzeslaus.github.io/code-quality-measures-foss4g-2022</a>
</section>
<section>
<h2>Bonus Content</h2>
</section>
<section>
<h2>Changes in Mindset</h2>
</section>
<section>
<h2>If It Ain't Broke, Don't Fix It, Or?</h2>
<p>
Why to Change Code which Works?
</p>
<p>
With languages, dependencies, operating systems changing fasts,
even stable code needs modifications.
So, you may as well update the code to latest standard because:
</p>
<ul>
<li>Non-compliant code broken.</li>
</ul>
<p>
Even if you don't care about best practices:
<p>
<ul>
<li>Hard to maintain code is broken.</li>
<li>Hard to change code is broken.</li>
</ul>
<p>
When you can apply automatic linters, maintaining and changing the code is simpler
because there is more checks in place.
</p>
</section>
<section>
<h2>Correctness Over Consistency</h2>
<p>
Should I changing surrounding code only because it is ugly?
</p>
<p>
Don't add bad code because the surrounding code is bad.
</p>
<p>
Leave the code in a better condition than when you found it.
</p>
</section>
<section>
<h2>Best Practices Change</h2>
Best practices are a moving target.
<ul>
<li>Black formatting may change with new version of Black (each year).</li>
<li>What is best formatting changes as new issues or use cases are discovered.</li>
<li>Formatting may change with new syntax available.</li>
<li>Best practices may change with new libraries, syntax, or security concerns.</li>
</ul>
<p>
So, the code will change (and that's fine).
</p>
</section>
<section>
<h2>Please, test!</h2>
<quote>
<em>The day when all manual testing will be obsolete because of some tool is very far away.</em>
<br>
<div style="text-align: right; padding-top: 1ex;">
— <a href="https://cppcheck.sourceforge.io">Cppcheck documentation</a>
</div>
</quote>
<p>
Linters work together with, not instead of manual testing and written tests.
</p>
</section>
<section>
<h2>More Linting Tools</h2>
</section>
<section>
<h2>Python: Flake8</h2>
<ul>
<li>Checks for errors and best practices in Python code</li>
<li>General PEP 8 compliance</li>
<li>
Combines:
<ul>
<li>PyFlakes (error checker), pycodestyle (formerly pep8), mccabe (complexity checker)</li>
</ul>
</li>
<li>
Some configuration required
<ul>
<li>Conflicts with Black</li>
<li>Special files may need special handling (e.g., <code>__init__.py</code>)</li>
</ul>
</li>
<li>Changes in code likely required</li>
</ul>
<p>
Check all code:
<pre><code data-trim class="no-highlight">
flake8
</code></pre>
</section>
<section>
<h2>Python: pydocstyle</h2>
<ul>
<li>Checks Python docstring conventions</li>
<li>PEP 257 Docstring Conventions (PEP 8 docstring parts)</li>
<li>Missing docstrings for public methods, "Return" versus "Returns", …</li>
</ul>
<p>
Check all code:
<pre><code data-trim class="no-highlight">
pydocstyle
</code></pre>
</section>
<section>
<h2>Python: isort</h2>
<ul>
<li>Sorts imports in a unified, configurable way</li>
<li>Configuration needed for Black compatibility</li>
</ul>
<p>
Apply formatting to all code:
<pre><code data-trim class="no-highlight">
isort .
</code></pre>
Check in CI:
<pre><code data-trim class="no-highlight">
isort --check-only .
</code></pre>
</section>
<section>
<h2>Python: Pylint</h2>
<ul>
<li>Errors, best practices, code smells in Python code</li>
<li>Makes suggestions for changes, refactoring</li>
<li>Complex configuration, runs long time</li>
<li>Imports the code (but does not run it)</li>
<li>Teaches how to write better code</li>
<li>Unlikely you will get it right without running it</li>
</ul>
<p>
General use:
<pre><code data-trim class="no-highlight">
pylint scripts/v.db.univar/v.db.univar.py
</code></pre>
In GRASS GIS with environment variables:
<pre><code data-trim class="no-highlight">
PYTHONPATH=$(grass --config python_path) \
LD_LIBRARY_PATH=$(grass --config path)/lib \
pylint scripts/v.db.univar/v.db.univar.py
</code></pre>
Or using <code>--exec</code>:
<pre><code data-trim class="no-highlight">
grass --tmp-location XY --exec pylint scripts/v.db.univar/v.db.univar.py
</code></pre>
</section>
<section>
<h2>C & C++: GCC, CLang</h2>
<ul>
<li>Errors, warnings, standards</li>
<li>During compilation, just enable additional switches</li>
<li>Steady increase in warnings enabled by Linux distributions</li>
<li>Warnings on one platform may be bugs on another</li>
</ul>